java - Insert into database AsyncTask error -


i make android application on movies. have database movies. in application display movies in listview , add new movie. have problem when try insert in database new movie. indeed, have n error in asynctask in doinbackground don't know why. when use debugger, have reject on begin of doinbackground @ line : string title = etitle.gettext().tostring();

so give java code :

    public class addmovie extends activity implements onclicklistener{   // edit , button user fill   private edittext etitle, eactors, edirector, ekind, edate, eimage, esummary ;   private button badd;    // progress dialog   private progressdialog pdialog;    //json parser class   //jsonparser jsonparser = new jsonparser();   private static final string tag_success = "success";   private static final string tag_message = "message";    @override   protected void oncreate(bundle savedinstancestate) {                super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_add_movie);               etitle = (edittext)findviewbyid(r.id.title);         eactors = (edittext)findviewbyid(r.id.actors);          edirector = (edittext)findviewbyid(r.id.director);         ekind = (edittext)findviewbyid(r.id.kind);         edate = (edittext)findviewbyid(r.id.date);         eimage = (edittext)findviewbyid(r.id.image);         esummary = (edittext)findviewbyid(r.id.summary);         badd = (button)findviewbyid(r.id.addmovies);         badd.setonclicklistener(this);               }   public void onclick(view v) {          // todo auto-generated method stub         switch (v.getid()) {         case r.id.addmovies:                     new attempmovie().execute();         // here have used, switch case, because on login activity may //also want show registration button, if user new ! can go //registration activity , other without switch //case.         default:               break;         }   }    class attempmovie extends asynctask<string, string, string> {          /**      * before starting background thread show progress dialog      * */         boolean failure = false;      @override     protected void onpreexecute() {         super.onpreexecute();         pdialog = new progressdialog(addmovie.this);         pdialog.setmessage("attempting add new movie...");         pdialog.setindeterminate(false);         pdialog.setcancelable(true);         pdialog.show();     }          @override         protected string doinbackground(string... args) {               // todo auto-generated method stub                // here check success tag         int success;         string title = etitle.gettext().tostring();         string actors = eactors.gettext().tostring();         string director = edirector.gettext().tostring();         string kind = ekind.gettext().tostring();         string date = edate.gettext().tostring();         string image = eimage.gettext().tostring();         string summary = esummary.gettext().tostring();         try {             // building parameters             list<namevaluepair> params = new arraylist<namevaluepair>();             params.add(new basicnamevaluepair("title", title));             params.add(new basicnamevaluepair("actors", actors));             params.add(new basicnamevaluepair("director", director));             params.add(new basicnamevaluepair("kind", kind));             params.add(new basicnamevaluepair("date", date));             params.add(new basicnamevaluepair("image", image));             params.add(new basicnamevaluepair("summary", summary));              log.d("request!", "starting");              jsonobject json = jsonfunctions.getjsonfromurl("http://10.0.0.35/bd_enterprise_mobility_movies/add_movie.php");              // checking  log json response             log.d("register attempt", json.tostring());              // success tag json             success = json.getint(tag_success);             if (success == 1)              {               log.d("successfully register!", json.tostring());               return json.getstring(tag_message);             }             else             {               log.d("login failure!", json.getstring(tag_message));               return json.getstring(tag_message);             }         } catch (jsonexception e) {             e.printstacktrace();         }          return null;         }         /**      * once background process done need  dismiss progress dialog asap      * **/     protected void onpostexecute(string message) {          pdialog.dismiss();         if (message != null){             intent = new intent(addmovie.this,mainactivity.class);             finish();             // finish() method used tell android os done current //activity now! moving other activity             startactivity(i);             toast.maketext(addmovie.this, message, toast.length_long).show();         }     }   }  } 

i give jsonfunctions.java

    public class jsonfunctions {  public static jsonobject getjsonfromurl(string url) {    inputstream = null;    string result = "";    jsonobject json = null;     // download json data url    try {        httpclient httpclient = new defaulthttpclient();        httppost httppost = new httppost(url);        httpresponse response = httpclient.execute(httppost);        httpentity entity = response.getentity();        = entity.getcontent();     } catch (exception e) {        log.e("log_tag", "error in http connection " + e.tostring());    }     // convert response string    try {        bufferedreader reader = new bufferedreader(new inputstreamreader(                is, "iso-8859-1"), 8);        stringbuilder sb = new stringbuilder();        string line = null;        while ((line = reader.readline()) != null) {            sb.append(line + "\n");        }        is.close();        result = sb.tostring();    } catch (exception e) {        log.e("log_tag", "error converting result " + e.tostring());    }     try {         json = new jsonobject(result);    } catch (jsonexception e) {        log.e("log_tag", "error parsing data " + e.tostring());    }     return json;  } } 

and error in logcat:

     03-20 18:28:19.753: e/androidruntime(14656): fatal exception: asynctask #3 03-20 18:28:19.753: e/androidruntime(14656): process: com.mickkoza.jsonkoza, pid: 14656 03-20 18:28:19.753: e/androidruntime(14656): java.lang.runtimeexception: error occured while executing doinbackground() 03-20 18:28:19.753: e/androidruntime(14656):    @ android.os.asynctask$3.done(asynctask.java:300) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.util.concurrent.futuretask.setexception(futuretask.java:222) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.util.concurrent.futuretask.run(futuretask.java:242) 03-20 18:28:19.753: e/androidruntime(14656):    @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.lang.thread.run(thread.java:818) 03-20 18:28:19.753: e/androidruntime(14656): caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.text.editable android.widget.edittext.gettext()' on null object reference 03-20 18:28:19.753: e/androidruntime(14656):    @ com.mickkoza.jsonkoza.addmovie$attempmovie.doinbackground(addmovie.java:81) 03-20 18:28:19.753: e/androidruntime(14656):    @ com.mickkoza.jsonkoza.addmovie$attempmovie.doinbackground(addmovie.java:1) 03-20 18:28:19.753: e/androidruntime(14656):    @ android.os.asynctask$2.call(asynctask.java:288) 03-20 18:28:19.753: e/androidruntime(14656):    @ java.util.concurrent.futuretask.run(futuretask.java:237) 03-20 18:28:19.753: e/androidruntime(14656):    ... 4 more 03-20 18:28:20.184: e/windowmanager(14656): android.view.windowleaked: activity com.mickkoza.jsonkoza.addmovie has leaked window com.android.internal.policy.impl.phonewindow$decorview{3e1b7378 v.e..... r......d 0,0-1026,288} added here 03-20 18:28:20.184: e/windowmanager(14656):     @ android.view.viewrootimpl.<init>(viewrootimpl.java:363) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:261) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.app.dialog.show(dialog.java:298) 03-20 18:28:20.184: e/windowmanager(14656):     @ com.mickkoza.jsonkoza.addmovie$attempmovie.onpreexecute(addmovie.java:74) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.os.asynctask.executeonexecutor(asynctask.java:587) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.os.asynctask.execute(asynctask.java:535) 03-20 18:28:20.184: e/windowmanager(14656):     @ com.mickkoza.jsonkoza.addmovie.onclick(addmovie.java:54) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.view.view.performclick(view.java:4756) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.view.view$performclick.run(view.java:19749) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.os.handler.handlecallback(handler.java:739) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.os.handler.dispatchmessage(handler.java:95) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.os.looper.loop(looper.java:135) 03-20 18:28:20.184: e/windowmanager(14656):     @ android.app.activitythread.main(activitythread.java:5221) 03-20 18:28:20.184: e/windowmanager(14656):     @ java.lang.reflect.method.invoke(native method) 03-20 18:28:20.184: e/windowmanager(14656):     @ java.lang.reflect.method.invoke(method.java:372) 03-20 18:28:20.184: e/windowmanager(14656):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) 03-20 18:28:20.184: e/windowmanager(14656):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694) 

thank help

michaƫl

one (or possibly all) of these views null:

string title = etitle.gettext().tostring(); string actors = eactors.gettext().tostring(); string director = edirector.gettext().tostring(); string kind = ekind.gettext().tostring(); string date = edate.gettext().tostring(); string image = eimage.gettext().tostring(); string summary = esummary.gettext().tostring(); 

possibly view ids you're referencing during oncreate find these views not correct?


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -