android - ProgressDialog crash in onPreExecute() method -
the progressdialog crashing in onpreexecute() method.
below code snippet:
public class testcasesactivity extends activity { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_testcases); xmlhelp = new xmlhelper(); configparser confparser = new configparser(); confparser.execute(); } private class configparser extends asynctask<void, void, void> { private progressdialog dialog; @override protected void onpreexecute() { dialog = new progressdialog(testcasesactivity.this); dialog.setmessage("loading testcases configuration..."); dialog.show(); } @override protected void doinbackground(void... params) { xmlhelp.getnumberofnodes(); return null; } @override protected void onpostexecute(void v) { dialog.dismiss(); // show test cases list here via listview } }
please suggest can wrong here. logcat prints given below:
07-30 08:13:50.511 20200-20200/? e/windowmanager﹕ android.view.windowleaked: activity com.testcasesactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{31a83555 v.e..... r......d 0,0-1026,348} added here @ android.view.viewrootimpl.(viewrootimpl.java:363) @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:262) @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) @ android.app.dialog.show(dialog.java:298) @ com.testcasesactivity$configparser.onpreexecute(testcasesactivity.java:41) @ android.os.asynctask.executeonexecutor(asynctask.java:587) @ android.os.asynctask.execute(asynctask.java:535) @ com.testcasesactivity.oncreate(testcasesactivity.java:30) @ android.app.activity.performcreate(activity.java:5984) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1105) @ android.app.activitythread.performlaunchactivity(activitythread.java:2254) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2361) @ android.app.activitythread.access$800(activitythread.java:147) @ android.app.activitythread$h.handlemessage(activitythread.java:1281) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5232) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:904) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:699)
there crash caused parser before:
07-30 08:40:32.651 22982-23154/? e/androidruntime﹕ fatal exception: asynctask #1 process: com.performance_tool, pid: 22982 java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:300) @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) @ java.util.concurrent.futuretask.setexception(futuretask.java:222) @ java.util.concurrent.futuretask.run(futuretask.java:242) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818) caused by: org.w3c.dom.domexception: 1 root element allowed @ org.apache.harmony.xml.dom.documentimpl.insertchildat(documentimpl.java:421) @ org.apache.harmony.xml.dom.innernodeimpl.appendchild(innernodeimpl.java:52) @ org.apache.harmony.xml.parsers.documentbuilderimpl.parse(documentbuilderimpl.java:306) @ org.apache.harmony.xml.parsers.documentbuilderimpl.parse(documentbuilderimpl.java:128) @ javax.xml.parsers.documentbuilder.parse(documentbuilder.java:107) @ com.xmlhelper.getnumberofnodes(xmlhelper.java:29) @ com.testcasesactivity$configparser.doinbackground(testcasesactivity.java:46) @ com.testcasesactivity$configparser.doinbackground(testcasesactivity.java:33) @ android.os.asynctask$2.call(asynctask.java:288) @ java.util.concurrent.futuretask.run(futuretask.java:237) at android.os.asynctask$serialexecutor$1.run(asynctask.java:231) at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) at java.lang.thread.run(thread.java:818)
solution 1: should dismiss progress dialog @ onpostexecute. this.
protected void onpostexecute(...){ // dismiss dialog here dialog.dismiss(); }
have done step?
solution 2: if done step on onpostexecute , still getting error means please check out next solution below,
pass context oncreate method asynctask this,
confparser.execute(testcasesactivity.this);
and async task this,
private class configparser extends asynctask<void, void, void> { private progressdialog dialog; context context; public configparser(context context){ this.context=context; } @override protected void onpreexecute() { dialog = new progressdialog(context); dialog.setmessage("loading testcases configuration..."); dialog.show(); } @override protected void onpostexecute(...){ // dismiss dialog here dialog.dismiss(); } }
Comments
Post a Comment