在我发布的上一个问题中(包含所有代码)
Unable to substantiate activity ComponentInfo - Null Pointer Exception
我有一个nullexception错误,如果击败那个运行时错误,我已经绊倒了另一个。日志猫是:
03-14 17:43:25.169: ERROR/AndroidRuntime(339): FATAL EXCEPTION: main
03-14 17:43:25.169: ERROR/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.dbtest/com.android.dbtest.ShowActivity}: java.lang.IllegalArgumentException: column '_id' does not exist
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.os.Looper.loop(Looper.java:123)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.ActivityThread.main(ActivityThread.java:3647)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at java.lang.reflect.Method.invoke(Method.java:507)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at dalvik.system.NativeStart.main(Native Method)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.widget.CursorAdapter.init(CursorAdapter.java:111)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:47)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:84)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at com.android.dbtest.ShowActivity.onCreate(ShowActivity.java:45)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
03-14 17:43:25.169: ERROR/AndroidRuntime(339): ... 11 more
一旦按下“显示”按钮并启动ShowActivity,就会出现此问题(上述链接的答案是关于在何处初始化listcontent) - 但是,由于colum _id,它现在似乎失败了。据我所知,这是在我的适配器中启动的。
任何帮助,非常好。
编辑:添加以下代码 - 并在下面添加评论
package com.android.dbtest;
import android.database.Cursor;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
public class AddActivity extends DatabaseTestActivity{
private SQLiteAdapter mySQLiteAdapter;
private String jobId;
SimpleCursorAdapter cursorAdapter;
Cursor cursor;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
// TODO Auto-generated method stub
final EditText jobIdInput = (EditText) findViewById(R.id.jobText);
//final EditText address1Input = (EditText) findViewById(R.id.add1Text); to be implemented
/**************************************************
*
* Get text Input from Edit Text Fields
*
***************************************************/
jobIdInput.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable id) {
jobId = jobIdInput.getText().toString();
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
/***************************************************
*
* initialise Database
*
*
***************************************************/
mySQLiteAdapter = new SQLiteAdapter(this);
/*****************************************************
* Listen for Confirm button press
******************************************************/
final Button confirm = (Button)findViewById(R.id.confirmButt);
confirm.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.insert(jobId);
mySQLiteAdapter.close();
}
});
/***********************************************************
* write jobId into SQl in the above method for button press
*
*************************************************************/
}
}
答案 0 :(得分:0)
正如@CornishDibley所说,我认为您需要从手机/模拟器中删除数据库。 据我所知,有两种方法可以做到这一点:
这应解决您的版本问题
提示:放置跟踪日志以调试程序并跟踪每个被执行的函数。看看你是否正在执行onCreat。如果没有,您的旧数据库文件仍然存在(据我所知)
答案 1 :(得分:0)
管理得出答案;从实际上没有创建数据库的事实。不受版本更改影响,而且解决方案是在主数据库测试活动中初始化数据库而不是AddActivty !!
当然没有我直接进入另一个NullPointerException - 但至少现在处理它是一个不同的问题!!