-1

在开始时一切正常,但是在我通过命令删除数据库之后:

this.deleteDatabase("databasename");

然后我的命令:

databasehelper.getWritableDatabase();

开始抛出异常

10-28 23:39:29.190: D/AndroidRuntime(15363): Shutting down VM
10-28 23:39:29.190: W/dalvikvm(15363): threadid=1: thread exiting with uncaught exception (group=0x40b5b300)
10-28 23:39:29.190: E/AndroidRuntime(15363): FATAL EXCEPTION: main
10-28 23:39:29.190: E/AndroidRuntime(15363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package/com.package.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=50; index=50
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.os.Looper.loop(Looper.java:137)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.ActivityThread.main(ActivityThread.java:4745)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at java.lang.reflect.Method.invokeNative(Native Method)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at java.lang.reflect.Method.invoke(Method.java:511)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at dalvik.system.NativeStart.main(Native Method)
10-28 23:39:29.190: E/AndroidRuntime(15363): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=50; index=50
10-28 23:39:29.190: E/AndroidRuntime(15363):    at com.package.DBHelper.onCreate(DBHelper.java:41)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at com.package.MainActivity.onCreate(MainActivity.java:28)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.Activity.performCreate(Activity.java:5008)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-28 23:39:29.190: E/AndroidRuntime(15363):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-28 23:39:29.190: E/AndroidRuntime(15363):    ... 11 more

我现在该怎么办?

4

2 回答 2

1

您应该学习如何阅读堆栈跟踪,因为它们是现代语言的无价值特性。您Activity无法启动,因为您尝试访问50具有 50 个元素的数组中索引处的元素,因此允许索引介于 0 和 49 之间:

java.lang.ArrayIndexOutOfBoundsException: length=50; index=50

这位于第 41 行的onCreate()方法中com.package.DBHelper

于 2012-10-28T18:23:17.237 回答
0

您可能需要先重新创建数据库吗?

于 2012-10-28T17:58:10.173 回答