In a previous question I posted (which contains all the code)
Unable to substantiate activity ComponentInfo – Null Pointer Exception
I had a nullexception error, howver having beaten that runtime error, i have tripped over another. the log cat is:
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
this problem occurs once the Show button has been pressed and the ShowActivity is launched (the answer to the above link regarding where to init the listcontent has been implemented) – however, it now seems to be failing due to the colum _id. Which as far as i can see is initilised in my adapter.
Any help , greatfully received.
EDIT: Added the following code – and addign comment below
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
*
*************************************************************/
}
}
Managed to work out the answer; from the fact that the database was not actually being created. Was not effected by version changes, moreover what the solution was was to initalise the database in the Main DatabaseTestActivity NOT the AddActivty!!
Of course no i have smacked right into another NullPointerException – but at least it is a different problem to deal with now!!