In my app, I have a list that shows a record of every patients medical treatments, the list shows their name, date of treatment. I want to be able to click on a specific entry and have it go to the edit screen.
The app adds new entries correctly, it lists the entry correctly but when I select an entry from the list I get the unable to start activity and the message is the Bind Value At Index 1 is null
My code is as follows
To build the list I am choosing from
public void fillMedicalList(String editPatientToGet){
//sql Query
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(Medical.MEDICAL_TABLE_NAME );
// build the return columns
String asColumnsToReturn[]= {
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_PATIENTID,
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_PATIENT_GROUP,
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_TREATMENT_DATE,
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_TREATMENT,
Medical.MEDICAL_TABLE_NAME + "." + Medical._ID};
//end of build columns to return
//build the where clause - find entries based on patient id
String valueToFind[] = {editPatientToGet};
//build the cursor
mCursor = queryBuilder.query(mDB, asColumnsToReturn, Medical.MEDICAL_PATIENTID + "=?", valueToFind,
null, null, null);
//manage the cursor
startManagingCursor(mCursor);
//use an adapter to bind the data to the listview
MedicalListAdapter adapter = new MedicalListAdapter(this, mCursor);
ListView av = (ListView) findViewById(R.id.medical_list);
av.setAdapter(adapter);
Now I begin to listen for a click of an item on the list
av.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
final long editMedicalid = id;
String WhatRecordIsIt = String.valueOf(editMedicalid);
Log.i("who is it", WhatRecordIsIt);
Log.d(DEBUG_TAG,WhatRecordIsIt);
editMedical(editMedicalid);
} //end of onClick for an item in the list
}); //end of OnItemClick Listener
} //end of fill PATIENTItem list
At this point my Log.i info shows that it has the correct Record ID.
Now my editMedical(editMedicalid) code is as follows
//we've clicked on a patient in the List list and now we're editing it
public void editMedical(Long id){
String astrArgs[] = {id.toString()};
String EditColumnsToReturn[]={
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_PATIENTID,
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_PATIENT_GROUP,
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_TREATMENT_DATE,
Medical.MEDICAL_TABLE_NAME + "." + Medical.MEDICAL_TREATMENT,
Medical.MEDICAL_TABLE_NAME + "." + Medical._ID};
Cursor c = mDB.query(Medical.MEDICAL_TABLE_NAME, EditColumnsToReturn,
Medical._ID + "=?", astrArgs, null, null, null, null);
c.moveToFirst();
final String strMedicalName =
c.getString(c.getColumnIndex(Medical.MEDICAL_PATIENTID));
Log.i("Patient's Name Is", strMedicalName);
Log.d(DEBUG_TAG,strMedicalName);
final String strMedicalType =
c.getString(c.getColumnIndex(Medical.MEDICAL_PATIENT_GROUP));
Log.i("what group", strMedicalType);
Log.d(DEBUG_TAG,strMedicalType);
final String strMedicalTreatmentDate =
c.getString(c.getColumnIndex(Medical.MEDICAL_TREATMENT_DATE));
Log.i("date", strMedicalTreatmentDate);
Log.d(DEBUG_TAG,strMedicalTreatmentDate);
final String strMedicalTreatment =
c.getString(c.getColumnIndex(Medical.MEDICAL_TREATMENT));
Log.i("treatment was", strMedicalTreatment);
Log.d(DEBUG_TAG,strMedicalTreatment);
final Long MedicalId =
c.getLong(c.getColumnIndex(Medical._ID));
String CurrentPatient = String.valueOf(MedicalId);
Log.i("Patient ID is", CurrentPatient);
Intent editMedical = new Intent(MedicalListActivity.this,
EditMedicalActivity.class);
editMedical.putExtra("patientName", strMedicalName);
editMedical.putExtra("patientGroup", strMedicalType);
editMedical.putExtra("treatmentDate", strMedicalTreatmentDate);
editMedical.putExtra("medicalTreatment", strMedicalTreatment);
String strCurrentPatient = String.valueOf(MedicalId);
editMedical.putExtra("medicalId", strCurrentPatient);
MedicalListActivity.this.startActivity(editMedical);
} //End of getting data needed to edit the record
My log.i shows the correct data being gathered but at this point I get error that it can't launch my EditMedicalActivity because the Bind Value At Index 1 is null
I've read and reread my code and can't find my mistake.
LogCat
02-15 15:33:35.769: E/AndroidRuntime(20339): FATAL EXCEPTION: main
02-15 15:33:35.769: E/AndroidRuntime(20339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.agmsi.medical/com.agmsi.medical.EditMedicalActivity}: java.lang.IllegalArgumentException: the bind value at index 1 is null
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.os.Handler.dispatchMessage(Handler.java:99)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.os.Looper.loop(Looper.java:130)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-15 15:33:35.769: E/AndroidRuntime(20339): at java.lang.reflect.Method.invokeNative(Native Method)
02-15 15:33:35.769: E/AndroidRuntime(20339): at java.lang.reflect.Method.invoke(Method.java:507)
02-15 15:33:35.769: E/AndroidRuntime(20339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
02-15 15:33:35.769: E/AndroidRuntime(20339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
02-15 15:33:35.769: E/AndroidRuntime(20339): at dalvik.system.NativeStart.main(Native Method)
02-15 15:33:35.769: E/AndroidRuntime(20339): Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:237)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:185)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:280)
02-15 15:33:35.769: E/AndroidRuntime(20339): at com.agmsi.medical.MedicalListActivity.fillMedicalList(MedicalListActivity.java:85)
02-15 15:33:35.769: E/AndroidRuntime(20339): at com.agmsi.medical.MedicalListActivity.onCreate(MedicalListActivity.java:42)
02-15 15:33:35.769: E/AndroidRuntime(20339): at com.agmsi.medical.EditMedicalActivity.onCreate(EditMedicalActivity.java:41)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-15 15:33:35.769: E/AndroidRuntime(20339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-15 15:33:35.769: E/AndroidRuntime(20339): ... 11 more
Well since the error occurs right after this section, I guess this is the part
Intent editMedical = new Intent(MedicalListActivity.this,
EditMedicalActivity.class);
editMedical.putExtra("patientName", strMedicalName);
editMedical.putExtra("patientGroup", strMedicalType);
editMedical.putExtra("treatmentDate", strMedicalTreatmentDate);
editMedical.putExtra("medicalTreatment", strMedicalTreatment);
String strCurrentPatient = String.valueOf(MedicalId);
editMedical.putExtra("medicalId", strCurrentPatient);
MedicalListActivity.this.startActivity(editMedical);
Right after this the error shows - so I'm not sure if it's something here or elsewhere which is why I posted the code from the two areas that are involved
This is a sqlite (database error).
after looking through your code and comparing it with my own it seems that editPatientToGet
which you are passing to the fillMedicalList(String editPatientToGet);
is null
your logcat can confirm it on this line:
02-15 15:33:35.769: E/AndroidRuntime(20339): at com.agmsi.medical.MedicalListActivity.fillMedicalList(MedicalListActivity.java:85)