我正在制作一个待办事项列表应用程序,现在我遇到了这个问题,我不知道如何解决它。任何人都可以帮助我。
这是我从LogCat获得的:
01-30 12:12:59.044: W/dalvikvm(30917): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-30 12:12:59.114: E/AndroidRuntime(30917): FATAL EXCEPTION: main
01-30 12:12:59.114: E/AndroidRuntime(30917): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.todo/com.todo.Todo}: java.lang.ArrayIndexOutOfBoundsException
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.os.Looper.loop(Looper.java:123)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-30 12:12:59.114: E/AndroidRuntime(30917): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 12:12:59.114: E/AndroidRuntime(30917): at java.lang.reflect.Method.invoke(Method.java:521)
01-30 12:12:59.114: E/AndroidRuntime(30917): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-30 12:12:59.114: E/AndroidRuntime(30917): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-30 12:12:59.114: E/AndroidRuntime(30917): at dalvik.system.NativeStart.main(Native Method)
01-30 12:12:59.114: E/AndroidRuntime(30917): Caused by: java.lang.ArrayIndexOutOfBoundsException
01-30 12:12:59.114: E/AndroidRuntime(30917): at com.todo.DatabaseHelper.GetAllItems(DatabaseHelper.java:140)
01-30 12:12:59.114: E/AndroidRuntime(30917): at com.todo.Todo.setupViews(Todo.java:61)
01-30 12:12:59.114: E/AndroidRuntime(30917): at com.todo.Todo.onCreate(Todo.java:25)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-30 12:12:59.114: E/AndroidRuntime(30917): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-30 12:12:59.114: E/AndroidRuntime(30917): ... 11 more
01-30 12:17:59.188: I/Process(30917): Sending signal. PID: 30917 SIG: 9
我想问题就在这里:
private Button add,delete,search,exit;
private Intent intent;
private ListView listView;
DatabaseHelper db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db=new DatabaseHelper(this);
db.open();
setupViews();
db.close();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.main_add_btn:
//open activity to add item
intent=new Intent(this, InsertItem.class);
startActivity(intent);
break;
case R.id.main_delete_btn:
//delete item
break;
case R.id.main_exit_btn:
finish();
break;
}
}
private void setupViews(){
add=(Button) findViewById(R.id.main_add_btn);
delete=(Button) findViewById(R.id.main_delete_btn);
search=(Button) findViewById(R.id.main_search_btn);
exit=(Button) findViewById(R.id.main_exit_btn);
add.setOnClickListener(this);
delete.setOnClickListener(this);
search.setOnClickListener(this);
exit.setOnClickListener(this);
listView=getListView();
// int l=(int) intent.getLongExtra("userID", -1);
Log.v("test","tuja");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, db.GetAllItems(1));
Log.v("test","tuja2");
setListAdapter(adapter);
}
}
这是我的第一篇文章,如果我搞砸了什么就很抱歉
答案 0 :(得分:1)
很明显,arrayindex超出绑定异常是在databasehelper类的GetAllItems方法中,并且很可能是由于cursor.getString(cursor.getColumnIndex(COLUMN_NAME))生成的;
但是,我建议您发布GetAllItems代码,以便我们为您提供帮助。