android - SoundPool crashes in two scenarios. Code for first scenario crashes -
@ian g. clifton here code first type of soundpool tried. when button load activity program fcs previous activity.
code starts here doesn't transfer over::::::
public class soundmanager { private soundpool msoundpool; private hashmap<integer, integer> msoundpoolmap; private audiomanager maudiomanager; private context mcontext; public soundmanager() { } public void initsounds(context thecontext) { mcontext = thecontext; msoundpool = new soundpool(16, audiomanager.stream_music, 0); msoundpoolmap = new hashmap<integer, integer>(); maudiomanager = (audiomanager)mcontext.getsystemservice(context.audio_service); } public void addsound(int index,int soundid) { msoundpoolmap.put(index, msoundpool.load(mcontext, soundid, 1)); } public void playsound(int index) { int streamvolume = maudiomanager.getstreamvolume(audiomanager.stream_music); msoundpool.play(msoundpoolmap.get(index), streamvolume, streamvolume, 1, 0, 1f); } public void playloopedsound(int index) { int streamvolume = maudiomanager.getstreamvolume(audiomanager.stream_music); msoundpool.play(msoundpoolmap.get(index), streamvolume, streamvolume, 1, -1, 1f); } }
:::::::::::::::::::activity:::::::::::::::::::::::::
activity { private soundmanager msoundmanager; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.nouns); msoundmanager = new soundmanager(); msoundmanager.initsounds(getbasecontext()); msoundmanager.addsound(1, r.raw.age); msoundmanager.addsound(2, r.raw.air); msoundmanager.addsound(3, r.raw.anger); msoundmanager.addsound(4, r.raw.animal); msoundmanager.addsound(5, r.raw.answer); msoundmanager.addsound(6, r.raw.apple); msoundmanager.addsound(7, r.raw.area); msoundmanager.addsound(8, r.raw.arm); msoundmanager.addsound(9, r.raw.art); msoundmanager.addsound(10, r.raw.atom); msoundmanager.addsound(11, r.raw.baby); msoundmanager.addsound(12, r.raw.lback); msoundmanager.addsound(13, r.raw.ball); msoundmanager.addsound(14, r.raw.band); msoundmanager.addsound(15, r.raw.bank); button onebutton = (button) this.findviewbyid(r.id.n1_button); onebutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(1); toast.maketext(nounsactivity.this, "age", toast.length_long).show(); } }); button twobutton = (button) this.findviewbyid(r.id.n2_button); twobutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(2); toast.maketext(nounsactivity.this, "air", toast.length_long).show(); } }); button threebutton = (button) this.findviewbyid(r.id.n3_button); threebutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(3); toast.maketext(nounsactivity.this, "anger", toast.length_long).show(); } }); button fourbutton = (button) this.findviewbyid(r.id.n4_button); fourbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(4); toast.maketext(nounsactivity.this, "animal", toast.length_long).show(); } }); button fivebutton = (button) this.findviewbyid(r.id.n5_button); fivebutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(5); toast.maketext(nounsactivity.this, "answer", toast.length_long).show(); } }); button sixbutton = (button) this.findviewbyid(r.id.n6_button); sixbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(6); toast.maketext(nounsactivity.this, "apple", toast.length_long).show(); } }); button sevenbutton = (button) this.findviewbyid(r.id.n7_button); sevenbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(7); toast.maketext(nounsactivity.this, "area", toast.length_long).show(); } }); button eightbutton = (button) this.findviewbyid(r.id.n8_button); eightbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(8); toast.maketext(nounsactivity.this, "arm", toast.length_long).show(); } }); button ninebutton = (button) this.findviewbyid(r.id.n9_button); ninebutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(9); toast.maketext(nounsactivity.this, "art", toast.length_long).show(); } }); button tenbutton = (button) this.findviewbyid(r.id.n10_button); tenbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(10); toast.maketext(nounsactivity.this, "atom", toast.length_long).show(); } }); button elevenbutton = (button) this.findviewbyid(r.id.n11_button); elevenbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(11); toast.maketext(nounsactivity.this, "baby", toast.length_long).show(); } }); button twelvebutton = (button) this.findviewbyid(r.id.n12_button); twelvebutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(12); toast.maketext(nounsactivity.this, "back", toast.length_long).show(); } }); button thirteenbutton = (button) this.findviewbyid(r.id.n13_button); thirteenbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(13); toast.maketext(nounsactivity.this, "ball", toast.length_long).show(); } }); button fourteenbutton = (button) this.findviewbyid(r.id.n14_button); fourteenbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(14); toast.maketext(nounsactivity.this, "band", toast.length_long).show(); } }); button fifteenbutton = (button) this.findviewbyid(r.id.n15_button); fifteenbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { msoundmanager.playsound(15); toast.maketext(nounsactivity.this, "bank", toast.length_long).show(); } }); button backbutton = (button) this.findviewbyid(r.id.back_button); backbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { finish(); } }); } }
::::::::::::tried soundpool , got error log:::::::::::::::
02-04 15:40:05.534: debug/dalvikvm(471): trying load lib /system/lib/libsoundpool.so 0x0 02-04 15:40:05.613: debug/dalvikvm(471): added shared lib /system/lib/libsoundpool.so 0x0 02-04 15:40:09.220: error/audiocache(172): heap size overflow! req size: 1049856, max size: 1048576 02-04 15:40:09.223: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.234: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.243: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.254: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.264: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.333: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.333: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.333: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.344: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.344: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.344: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.353: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.353: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.353: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.353: error/audiocache(172): heap size overflow! req size: 1052672, max size: 1048576 02-04 15:40:09.364: error/audiocache(172): heap size overflow! req size: 1051392, max size: 1048576 02-04 15:40:15.313: warn/activitymanager(179): launch timeout has expired, giving wake lock! 02-04 15:40:15.363: warn/activitymanager(179): activity idle timeout historyrecord{43c86078 com.blumouse.mnekrenfull2/.nounsactivity} 02-04 15:40:17.943: debug/androidruntime(471): shutting down vm 02-04 15:40:18.133: warn/dalvikvm(471): threadid=3: thread exiting uncaught exception (group=0x4001b188) 02-04 15:40:18.186: error/androidruntime(471): uncaught handler: thread main exiting due uncaught exception 02-04 15:40:19.433: error/androidruntime(471): java.lang.runtimeexception: unable start activity componentinfo{package.nameactivity}: java.lang.nullpointerexception 02-04 15:40:19.433: error/androidruntime(471): @ android.app.activitythread.performlaunchactivity(activitythread.java:2496) 02-04 15:40:19.433: error/androidruntime(471): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2512) 02-04 15:40:19.433: error/androidruntime(471): @ android.app.activitythread.access$2200(activitythread.java:119) 02-04 15:40:19.433: error/androidruntime(471): @ android.app.activitythread$h.handlemessage(activitythread.java:1863) 02-04 15:40:19.433: error/androidruntime(471): @ android.os.handler.dispatchmessage(handler.java:99) 02-04 15:40:19.433: error/androidruntime(471): @ android.os.looper.loop(looper.java:123) 02-04 15:40:19.433: error/androidruntime(471): @ android.app.activitythread.main(activitythread.java:4363) 02-04 15:40:19.433: error/androidruntime(471): @ java.lang.reflect.method.invokenative(native method) 02-04 15:40:19.433: error/androidruntime(471): @ java.lang.reflect.method.invoke(method.java:521) 02-04 15:40:19.433: error/androidruntime(471): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:860) 02-04 15:40:19.433: error/androidruntime(471): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618) 02-04 15:40:19.433: error/androidruntime(471): @ dalvik.system.nativestart.main(native method) 02-04 15:40:19.433: error/androidruntime(471): caused by: java.lang.nullpointerexception 02-04 15:40:19.433: error/androidruntime(471): @ package.nameactivity.oncreate(nameactivity.java:168) 02-04 15:40:19.433: error/androidruntime(471): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 02-04 15:40:19.433: error/androidruntime(471): @ android.app.activitythread.performlaunchactivity(activitythread.java:2459) 02-04 15:40:19.433: error/androidruntime(471): ... 11 more 02-04 15:40:19.573: info/process(179): sending signal. pid: 471 sig: 3 02-04 15:40:19.583: info/dalvikvm(471): threadid=7: reacting signal 3 02-04 15:40:21.363: info/dalvikvm(471): wrote stack trace '/data/anr/traces.txt' 02-04 15:40:29.603: debug/dalvikvm(351): gc freed 44 objects / 2136 bytes in 8302ms 02-04 15:40:29.863: debug/dalvikvm(227): gc freed 2193 objects / 127504 bytes in 1879ms
i found problem. not problem these parts of code. chirag shah led me answer sudgestion. looked through code , found had locked buttons out of create section of code in previous activity.
i had
private button button1;
this before oncreate method when removed private part.
button button1;
now works fine.
Comments
Post a Comment