【发布时间】:2013-12-30 11:04:41
【问题描述】:
谁能确定出了什么问题,或者给我任何线索?我认为它在当前活动(CreateProfileActivity)中,在这个buttonClick方法中:
public void saveUserClick(View view){
saveUserDetails();
insertUserToDB();
Log.d("yo", "yoyoyo");
dbHelper.logDataBase();
}
尤其是dbHelper.logDataBase();这一行
这是方法声明:
public void logDataBase(){
// Getting all clothing items
Log.d("Get database Items", "Getting all database items");
List<ClothingItem> allClothingItems = this.getAllClothingItems();
List<AppUser> allAppUsers = this.getAllAppUsers();
for (ClothingItem clothingItem : allClothingItems) {
Log.d("ClothingItem", clothingItem.getIdString());
}
for (AppUser appUser : allAppUsers) {
Log.d("User", appUser.getImagePath());
}
}
这里是 Logcat:
12-30 02:39:57.499: D/dalvikvm(277): GC_EXPLICIT freed 5474 objects / 286208 bytes in 138ms
12-30 02:41:48.227: D/yo(277): yoyoyo
12-30 02:41:48.227: D/Get database Items(277): Getting all database items
12-30 02:41:48.227: E/dbHelper(277): SELECT * FROM ClothingItem
12-30 02:41:48.247: E/dbHelper(277): SELECT * FROM AppUser
12-30 02:41:48.247: D/ClothingItem(277): 1
12-30 02:41:48.247: D/ClothingItem(277): 2
12-30 02:41:48.247: D/ClothingItem(277): 3
12-30 02:41:48.247: D/ClothingItem(277): 4
12-30 02:41:48.247: D/ClothingItem(277): 5
12-30 02:41:48.247: D/ClothingItem(277): 6
12-30 02:41:48.247: D/ClothingItem(277): 7
12-30 02:41:48.247: D/ClothingItem(277): 8
12-30 02:41:48.247: D/ClothingItem(277): 9
12-30 02:41:48.247: D/ClothingItem(277): 10
12-30 02:41:48.247: D/ClothingItem(277): 11
12-30 02:41:48.247: D/ClothingItem(277): 12
12-30 02:41:48.247: D/User(277): content://media/external/images/media/1
12-30 02:41:48.247: D/User(277): content://media/external/images/media/1
12-30 02:41:48.247: D/AndroidRuntime(277): Shutting down VM
12-30 02:41:48.247: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-30 02:41:48.267: E/AndroidRuntime(277): FATAL EXCEPTION: main
12-30 02:41:48.267: E/AndroidRuntime(277): java.lang.IllegalStateException: Could not execute method of the activity
12-30 02:41:48.267: E/AndroidRuntime(277): at android.view.View$1.onClick(View.java:2072)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.view.View.performClick(View.java:2408)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.view.View$PerformClick.run(View.java:8816)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.os.Handler.handleCallback(Handler.java:587)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:92)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-30 02:41:48.267: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 02:41:48.267: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
12-30 02:41:48.267: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-30 02:41:48.267: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-30 02:41:48.267: E/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
12-30 02:41:48.267: E/AndroidRuntime(277): Caused by: java.lang.reflect.InvocationTargetException
12-30 02:41:48.267: E/AndroidRuntime(277): at com.btf271.fashionassistant.CreateProfileActivity.saveUserClick(CreateProfileActivity.java:50)
12-30 02:41:48.267: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 02:41:48.267: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.view.View$1.onClick(View.java:2067)
12-30 02:41:48.267: E/AndroidRuntime(277): ... 11 more
12-30 02:41:48.267: E/AndroidRuntime(277): Caused by: java.lang.NullPointerException: println needs a message
12-30 02:41:48.267: E/AndroidRuntime(277): at android.util.Log.println_native(Native Method)
12-30 02:41:48.267: E/AndroidRuntime(277): at android.util.Log.d(Log.java:122)
12-30 02:41:48.267: E/AndroidRuntime(277): at com.btf271.dbhelper.dbhelper.logDataBase(dbhelper.java:138)
12-30 02:41:48.267: E/AndroidRuntime(277): ... 15 more
由于某种原因,VM 似乎在使用 logDatabase 方法后关闭。当我将其注释掉时,它不会关闭。
【问题讨论】:
-
你能把你的dbHelper类源代码和你初始化它的代码放在哪里。
-
尝试在你的方法中注释掉 Log.d 调用
标签: android logcat illegalstateexception