gpt4 book ai didi

java.lang.IllegalArgumentException : the bind value at index 1 is null

转载 作者:行者123 更新时间:2023-11-30 07:41:30 28 4
gpt4 key购买 nike

我想进行查询并使用用户在编辑文本中输入的值,因为条件是 where 子句。在数据库helper.java类中:查询如下:

数据库助手.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;
}

在 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();

}

运行应用程序并单击按钮时,出现以下错误:

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)

请帮忙..提前谢谢

最佳答案

您分配给局部变量 ,而不是分配给类成员:

 String value = id_p.getText().toString();

应该是

 value = id_p.getText().toString();

否则 SQL 语句中的 ExaminatFragment.value 将为 null

您可能想要更改数据库方法以接受参数:

public Cursor patientHisto ( String value ) {
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[] {value} );
return res;
}

并且不依赖静态字段来传递该值。然后,您对该方法的调用将更改为

 Cursor res = myDB.patientHisto(value);

关于java.lang.IllegalArgumentException : the bind value at index 1 is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34630460/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com