android - NullPointerException in userdefined method "insert" in datahelper class -


this question has answer here:

this logcat

07-11 04:34:41.360: e/androidruntime(10132): fatal exception: main 07-11 04:34:41.360: e/androidruntime(10132): process:app.example.movierating, pid: 10132 07-11 04:34:41.360: e/androidruntime(10132): java.lang.nullpointerexception 07-11 04:34:41.360: e/androidruntime(10132): @ model.datahelper.insert(datahelper.java:75) 07-11 04:34:41.360: e/androidruntime(10132):    @ app.example.movierating.mainactivity1$1.onclick(mainactivity1.java:85) 07-11 04:34:41.360: e/androidruntime(10132):    @ android.view.view.performclick(view.java:4424) 07-11 04:34:41.360: e/androidruntime(10132):    @ android.view.view$performclick.run(view.java:18383) 07-11 04:34:41.360: e/androidruntime(10132):    @ android.os.handler.handlecallback(handler.java:733) 07-11 04:34:41.360: e/androidruntime(10132):    @ android.os.handler.dispatchmessage(handler.java:95) 07-11 04:34:41.360: e/androidruntime(10132):    @ android.os.looper.loop(looper.java:137) 07-11 04:34:41.360: e/androidruntime(10132):    @ android.app.activitythread.main(activitythread.java:4998) 07-11 04:34:41.360: e/androidruntime(10132):    @ java.lang.reflect.method.invokenative(native method) 07-11 04:34:41.360: e/androidruntime(10132):    @ java.lang.reflect.method.invoke(method.java:515) 07-11 04:34:41.360: e/androidruntime(10132):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:777) 07-11 04:34:41.360: e/androidruntime(10132):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:593) 07-11 04:34:41.360: e/androidruntime(10132):    @ dalvik.system.nativestart.main(native method) 

this datahelper class code after filling mainactivity layout ...on saving appp closes unfortunately beacuse of above error. me because cant make out null exception , how go learner.

package model;  import java.util.collection;  import android.content.contentvalues; import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqlitedatabase.cursorfactory; import android.database.sqlite.sqliteopenhelper; import android.util.log;  public class datahelper extends sqliteopenhelper {  static string dbname="info.db"; static string tablename="records"; sqlitedatabase db;  static int dbversion=1;  public datahelper(context context)         {     super(context,dbname,  null, dbversion);     // todo auto-generated constructor stub }  @override public void oncreate(sqlitedatabase arg0) {     // todo auto-generated method stub     arg0.execsql("createtable" + tablename + "(id integer.primary key autoincrement, name1 text,yr1 text,dur1 text,starcast1 text,review1 text,dir1 text, genre1 text)");     log.e("sqlitedata", "tablecreated");     }  @override public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {     // todo auto-generated method stub     arg0.execsql("drop table if exists" + tablename);     oncreate(arg0); }    public boolean insert(string name1, string genre1, string yr1, string dur1,float ratingbar1, string review1, string starcast1, string dir1) {     // todo auto-generated method stub      boolean result;         try         {             db=this.getwritabledatabase();             contentvalues c=new contentvalues();             c.put("name", name1);             c.put("genre", genre1);             c.put("yr", yr1);             c.put("dur", dur1);             c.put("review", review1);             c.put("starcast", starcast1);             c.put("dir", dir1);             long res=db.insert(tablename, null , c);              if(res>0)             {                 result=true;                 //return result;             }             else             {                 result=false;                 //return result;             }         }         catch(exception ex)         {             log.e("error",ex.tostring());         }                 {             db.close();         }         return result=false;  }    } 

returns , stuck

change code below in oncreate;

arg0.execsql("create table " + tablename + "(id integer primary key autoincrement, name text,yr text,dur text,starcast text,review text,dir text, genre text)"); 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -