android - Trying to append values to the textview from inside while loop -
i'm trying values database , display in textview using function in supporter class. 2 classes mainactivity.java & dbhelper.java.
onclick function in mainactivity is:
public void see(view v){ dbhelper.seerecord(s, ss); //tv.append(s,ss); }
function in dbhelper retrieve data is:
private string []cols = new string[]{"name","id"}; public void seerecord(string a, int b){ db= this.getreadabledatabase(); cursor c = db.rawquery("select * vijay1", null); if(c.movetofirst()){ while(c.movetonext()){ string nameintable = c.getstring(c.getcolumnindex(cols[0])); int idintable = c.getint(c.getcolumnindex(cols[1])); a=nameintable; b=idintable; **main.tv.append(b+". "+a+"\n");** //main object of activity class } c.close(); db.close(); } }
now, if append value textview in onclick function, last entered value db displayed quite obvious.
but if append in while loop of dbhelper class (so every row append values textview), app crashes. couldnt find reasons. pls help.
stacktrace:
07-31 12:50:01.537: e/androidruntime(486): fatal exception: main 07-31 12:50:01.537: e/androidruntime(486): java.lang.illegalstateexception: not execute method of activity 07-31 12:50:01.537: e/androidruntime(486): @ android.view.view$1.onclick(view.java:2072) 07-31 12:50:01.537: e/androidruntime(486): @ android.view.view.performclick(view.java:2408) 07-31 12:50:01.537: e/androidruntime(486): @ android.view.view$performclick.run(view.java:8816) 07-31 12:50:01.537: e/androidruntime(486): @ android.os.handler.handlecallback(handler.java:587) 07-31 12:50:01.537: e/androidruntime(486): @ android.os.handler.dispatchmessage(handler.java:92) 07-31 12:50:01.537: e/androidruntime(486): @ android.os.looper.loop(looper.java:123) 07-31 12:50:01.537: e/androidruntime(486): @ android.app.activitythread.main(activitythread.java:4627) 07-31 12:50:01.537: e/androidruntime(486): @ java.lang.reflect.method.invokenative(native method) 07-31 12:50:01.537: e/androidruntime(486): @ java.lang.reflect.method.invoke(method.java:521) 07-31 12:50:01.537: e/androidruntime(486): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 07-31 12:50:01.537: e/androidruntime(486): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 07-31 12:50:01.537: e/androidruntime(486): @ dalvik.system.nativestart.main(native method) 07-31 12:50:01.537: e/androidruntime(486): caused by: java.lang.reflect.invocationtargetexception 07-31 12:50:01.537: e/androidruntime(486): @ com.example.databaseaccess.mainactivity.see(mainactivity.java:44) 07-31 12:50:01.537: e/androidruntime(486): @ java.lang.reflect.method.invokenative(native method) 07-31 12:50:01.537: e/androidruntime(486): @ java.lang.reflect.method.invoke(method.java:521) 07-31 12:50:01.537: e/androidruntime(486): @ android.view.view$1.onclick(view.java:2067) 07-31 12:50:01.537: e/androidruntime(486): ... 11 more 07-31 12:50:01.537: e/androidruntime(486): caused by: java.lang.nullpointerexception 07-31 12:50:01.537: e/androidruntime(486): @ com.example.databaseaccess.dbhelper.seerecord(dbhelper.java:78) 07-31 12:50:01.537: e/androidruntime(486): ... 15 more
Comments
Post a Comment