android - SQlite Database NullPointerException when inserting data when button in dialog is clicked -


i have been working on creating , inserting data in table. have dialog box expandable list. user selects few things , clicks done; calls class creates table , insert data.


the flow of program :

mainactivity -> oncreate (added adapters, make dialog expandable list) -> onresume -> callasync -> doinbackground (dao instance, instance.open, dostuff, instance.close).

dao constructor -> (helper instance); dao open -> (db = helper.getwritabledatabase())

helper oncreate -> execsql commands -> tables (db) constructor -> tables made s

dialog -> makestuff -> onclick -> (calculate array used make table) -> tables(array) constructor -> error here showing npe.


i have pushed current files github. after oncreate method of helper completed, database closed? dont see other reason database showing null pointer exception. working till last night before adding table_ncup.

logcat

    04-14 10:12:26.654: e/androidruntime(2560): fatal exception: main 04-14 10:12:26.654: e/androidruntime(2560): process: com.example.try_sqlite_url, pid: 2560 04-14 10:12:26.654: e/androidruntime(2560): java.lang.nullpointerexception 04-14 10:12:26.654: e/androidruntime(2560):     @ com.example.try_sqlite_url.tables.<init>(tables.java:22) 04-14 10:12:26.654: e/androidruntime(2560):     @ com.example.try_sqlite_url.dialogmaker$1.onclick(dialogmaker.java:70) 04-14 10:12:26.654: e/androidruntime(2560):     @ android.view.view.performclick(view.java:4438) 04-14 10:12:26.654: e/androidruntime(2560):     @ android.view.view$performclick.run(view.java:18422) 04-14 10:12:26.654: e/androidruntime(2560):     @ android.os.handler.handlecallback(handler.java:733) 04-14 10:12:26.654: e/androidruntime(2560):     @ android.os.handler.dispatchmessage(handler.java:95) 04-14 10:12:26.654: e/androidruntime(2560):     @ android.os.looper.loop(looper.java:136) 04-14 10:12:26.654: e/androidruntime(2560):     @ android.app.activitythread.main(activitythread.java:5017) 04-14 10:12:26.654: e/androidruntime(2560):     @ java.lang.reflect.method.invokenative(native method) 04-14 10:12:26.654: e/androidruntime(2560):     @ java.lang.reflect.method.invoke(method.java:515) 04-14 10:12:26.654: e/androidruntime(2560):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 04-14 10:12:26.654: e/androidruntime(2560):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 04-14 10:12:26.654: e/androidruntime(2560):     @ dalvik.system.nativestart.main(native method) 

update:

thanks @laalto, reckon variable making 2 different instances right now, , second instance not have database initialized. tried using getinstance way refering here. instance while calling tables through onclick in dialog null. changed code are:

tables.java

public static tables tableinstance;  public static tables getinstance(sqlitedatabase db) {     if (tableinstance == null) {         log.d("table", "in table getinstance db");         tableinstance = new tables(db);     }     return tableinstance; }  public static tables getinstance(int[] array) {     log.d("table", "in table getinstance array");     return tableinstance; } 

calling tables instance after clicking button in dialog:

tables instance = tables.getinstance(ncup); instance.tables(ncup); // <----- null! dialog.dismiss(); 

your tables has 2 constructors , 1 you're using public tables(int[] ncup_array) not initialize database member variable.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -