java - Syntactical Errors in my Android media player -
these syntactical errors, , don't know how figure out,
current_song cannot resolved variable
multiple markers @ line, song_url cannot resolved variable
how resolve above errors. unable access song_url , current_song in methods, instance in,
next.setonclicklistener(new view.onclicklistener(){ @override public void onclick(view v) { // todo auto-generated method stub mp.stop(); ++current_song; mp.setdatasource(song_url[current_song]); mp.start(); } });
my complete code,
public class jsonmedia extends activity { private mediaplayer mp; button play, pause, next; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.jsonview); mp = new mediaplayer(); mp.setaudiostreamtype(audiomanager.stream_music); play = (button) findviewbyid(r.id.play); pause = (button) findviewbyid(r.id.pause); next = (button) findviewbyid(r.id.next); try { // create url desired page url url = new url("http://reallifethug.webs.com/temp_list.txt"); bufferedreader in = new bufferedreader(new inputstreamreader( url.openstream())); int ch, current_song = 0, eof = -1; // end of file string list[]; string str = ""; while ((ch = in.read()) != eof) str += (char) ch; in.close(); list = str.split("\n"); (ch = 0; ch < list.length; ++ch) list[ch] += "\n"; string song_name[] = new string[list.length]; string song_url[] = new string[list.length]; (int = 0; < list.length; i++) { song_name[i] = ""; song_url[i] = ""; int = 0; char c; while ((c = list[i].charat(a++)) != ' ') song_name[i] += c; while ((c = list[i].charat(a++)) != '\n') song_url[i] += c; } mp.setdatasource(song_url[current_song]); } catch (illegalargumentexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (securityexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (illegalstateexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } mp.prepareasync(); play.setenabled(false); mp.setonpreparedlistener(new mediaplayer.onpreparedlistener() { @override public void onprepared(mediaplayer mp) { // todo auto-generated method stub play.setenabled(true); } }); play.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub mp.start(); } }); pause.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub mp.pause(); } }); next.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub mp.stop(); ++current_song; mp.setdatasource(song_url[current_song]); mp.start(); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.jsonmedia, menu); return true; } }
log cat, 05-18 17:37:14.272: d/androidruntime(486): shutting down vm 05-18 17:37:14.272: w/dalvikvm(486): threadid=1: thread exiting uncaught exception (group=0x40015560) 05-18 17:37:14.291: e/androidruntime(486): fatal exception: main 05-18 17:37:14.291: e/androidruntime(486): java.lang.nullpointerexception 05-18 17:37:14.291: e/androidruntime(486): @ com.hiphop.streamingmediaplayer.jsonmedia$4.onclick(jsonmedia.java:114) 05-18 17:37:14.291: e/androidruntime(486): @ android.view.view.performclick(view.java:2485) 05-18 17:37:14.291: e/androidruntime(486): @ android.view.view$performclick.run(view.java:9080) 05-18 17:37:14.291: e/androidruntime(486): @ android.os.handler.handlecallback(handler.java:587) 05-18 17:37:14.291: e/androidruntime(486): @ android.os.handler.dispatchmessage(handler.java:92) 05-18 17:37:14.291: e/androidruntime(486): @ android.os.looper.loop(looper.java:123) 05-18 17:37:14.291: e/androidruntime(486): @ android.app.activitythread.main(activitythread.java:3683) 05-18 17:37:14.291: e/androidruntime(486): @ java.lang.reflect.method.invokenative(native method) 05-18 17:37:14.291: e/androidruntime(486): @ java.lang.reflect.method.invoke(method.java:507) 05-18 17:37:14.291: e/androidruntime(486): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 05-18 17:37:14.291: e/androidruntime(486): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 05-18 17:37:14.291: e/androidruntime(486): @ dalvik.system.nativestart.main(native method) 05-18 17:37:16.301: i/process(486): sending signal. pid: 486 sig: 9
you have song_url
defined inside try
block hence not available outside.
so declare them before try
:
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.jsonview); mp = new mediaplayer(); mp.setaudiostreamtype(audiomanager.stream_music); play = (button) findviewbyid(r.id.play); pause = (button) findviewbyid(r.id.pause); next = (button) findviewbyid(r.id.next); int current_song = 0; string song_url[] = null; try { .... .... song_url = new string[list.length]; }
Comments
Post a Comment