Android Async Task Do in Background Error -
am trying create activity connects database on local host, after user fills form form submitted localhost using asyntask.do in background method. getting error , not quite sure wrong, please need help.
this logcat
`01-30 06:03:10.451: e/androidruntime(1332): fatal exception: asynctask #1 01-30 06:03:10.451: e/androidruntime(1332): java.lang.runtimeexception: error occured while executing doinbackground() 01-30 06:03:10.451: e/androidruntime(1332): @ android.os.asynctask$3.done(asynctask.java:278) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.futuretask.run(futuretask.java:137) 01-30 06:03:10.451: e/androidruntime(1332): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:208) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 01-30 06:03:10.451: e/androidruntime(1332): @ java.lang.thread.run(thread.java:856) 01-30 06:03:10.451: e/androidruntime(1332): caused by: java.lang.nullpointerexception 01-30 06:03:10.451: e/androidruntime(1332): @ com.oose.buddiev2.registeractivity$createnewuser.doinbackground(registeractivity.java:101) 01-30 06:03:10.451: e/androidruntime(1332): @ com.oose.buddiev2.registeractivity$createnewuser.doinbackground(registeractivity.java:1) 01-30 06:03:10.451: e/androidruntime(1332): @ android.os.asynctask$2.call(asynctask.java:264) 01-30 06:03:10.451: e/androidruntime(1332): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 01-30 06:03:10.451: e/androidruntime(1332): ... 5 more`
this async task in activity
class createnewuser extends asynctask<string, string, string> { /** * before starting background thread show progress dialog * */ @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(registeractivity.this); pdialog.setmessage("creating user.."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } /** * creating user * */ protected string doinbackground(string... args) { string usernamestring = usernameedittext.gettext().tostring(); string emailstring = emailedittext.gettext().tostring(); string passwordstring = passwordedittext.gettext().tostring(); // building parameters list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("username", usernamestring)); params.add(new basicnamevaluepair("email", emailstring)); params.add(new basicnamevaluepair("password", passwordstring)); // getting json object // note create product url accepts post method jsonobject json = jsonparser.makehttprequest(url_create_user, "post", params); // check logcat response log.d("create response", json.tostring()); // check success tag try { int success = json.getint(tag_success); // int success = 1; if (success == 1) { // created product intent = new intent(getapplicationcontext(), loginactivity.class); startactivity(i); // closing screen finish(); } else { // failed create product } } catch (jsonexception e) { e.printstacktrace(); } return null; } /** * after completing background task dismiss progress dialog * **/ protected void onpostexecute(string file_url) { // dismiss dialog once done pdialog.dismiss(); }
you cannot in doinbackground.
try removing doinbackground or can put in onpostexecute():
startactivity(i); finish();
Comments
Post a Comment