android - IllegalStateException: Could not execute method of the activity -
can explain me why i'm getting java.lang.illegalstateexception: not execute method of activity when trying click button data database?
my xml code has onclick this:
<button android:layout_width="0dip" android:layout_height="wrap_content" android:text="delete" android:id="@+id/btndelete" android:layout_weight="1" android:onclick="onclick_deleteall"/>
my mainactivity code:
public void onclick_deleteall(view view){ dbtools dbtools = new dbtools(getapplicationcontext()) float total = dbtools.total(); }
my database class(dbtools.java) code:
public float total(){ float total = 0; sqlitedatabase db = getreadabledatabase(); cursor cursor = db.rawquery("select sum("+ price +") " + table_item_sell, null); if (cursor.movetofirst()){ total = float.parsefloat(cursor.getstring(0)); } return total; }
don't know what's wrong because happens when method try execute return data. code above, returns float.
error:
java.lang.illegalstateexception: not execute method of activity @ android.view.view$1.onclick(view.java:3591) @ android.view.view.performclick(view.java:4084) @ android.view.view$performclick.run(view.java:16966) @ android.os.handler.handlecallback(handler.java:615) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4745) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) @ dalvik.system.nativestart.main(native method) caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ android.view.view$1.onclick(view.java:3586) @ android.view.view.performclick(view.java:4084) at android.view.view$performclick.run(view.java:16966) at android.os.handler.handlecallback(handler.java:615) at android.os.handler.dispatchmessage(handler.java:92) at android.os.looper.loop(looper.java:137) at android.app.activitythread.main(activitythread.java:4745) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:511) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) at com.android.internal.os.zygoteinit.main(zygoteinit.java:553) at dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ java.lang.stringtoreal.parsefloat(stringtoreal.java:285) @ java.lang.float.parsefloat(float.java:300) @ com.jcarlapp.carl.amystore.dbtools.total(dbtools.java:151) @ com.jcarlapp.carl.amystore.mainactivity.onclick_deleteall(mainactivity.java:306) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:511) at android.view.view$1.onclick(view.java:3586) at android.view.view.performclick(view.java:4084) at android.view.view$performclick.run(view.java:16966) at android.os.handler.handlecallback(handler.java:615) at android.os.handler.dispatchmessage(handler.java:92) at android.os.looper.loop(looper.java:137) at android.app.activitythread.main(activitythread.java:4745) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:511) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) at com.android.internal.os.zygoteinit.main(zygoteinit.java:553) at dalvik.system.nativestart.main(native method)
it caused npe
caused by: java.lang.nullpointerexception @ java.lang.stringtoreal.parsefloat(stringtoreal.java:285) @ java.lang.float.parsefloat(float.java:300) @ com.jcarlapp.carl.amystore.dbtools.total(dbtools.java:151)
it seems cursor.getstring(0)
returns null
in method total.
i assume have no rows in table calculate sum.
Comments
Post a Comment