I want to make a query and use the value entered by the user in the edittext as condition is the where clause. In database helper.java class: The query is the following:
Databasehelper.java:
public Cursor patientHisto ( ) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery (" select dateap,diagnostic,prestreatment from patients_table, appointments_table, examinations_table where patients_table.id = appointments_table.idp and appointments_table.idap = examinations_table.id_ap and ID = ? order by name, familyname asc" , new String[] {ExaminatFragment.value} );
return res;
}
In ExaminatFragment.java:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_examinat, parent, false);
myDB = new DatabaseHelper(getActivity());
id_p = (EditText)v.findViewById(R.id.id_p_text);
String value = id_p.getText().toString();
getPatHisto( );
return v;
}
public void getPatHisto( ) {
showhp.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor res = myDB.patientHisto();
if (res.getCount() == 0){
showMessage("Patient history", "No patient history found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext()){
buffer.append("Dateap:"+res.getString(0)+"\n");
buffer.append("Diagnostic:"+res.getString(1)+"\n");
buffer.append("Prestreatment:"+res.getString(2)+"\n\n");
}
showMessage("Patient's history", buffer.toString());
}
}
);
}
public void showMessage(String title, String Message){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();
}
When running the application and clicking on the button it gives me the following error:
01-06 10:55:57.510: E/AndroidRuntime(1952): FATAL EXCEPTION: main
01-06 10:55:57.510: E/AndroidRuntime(1952): Process: com.example.appointapp, PID: 1952
01-06 10:55:57.510: E/AndroidRuntime(1952): java.lang.IllegalArgumentException: the bind value at index 1 is null
01-06 10:55:57.510: E/AndroidRuntime(1952): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
01-06 10:55:57.510: E/AndroidRuntime(1952): at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
Please help.. thank you in advance
Aucun commentaire:
Enregistrer un commentaire