我尝试从我的数据库中选择与在我的列表视图中单击的项目匹配的特定字段,当我运行应用程序并单击应用程序崩溃的任何项目时,我的代码有什么问题?
这是来自 logcat 的错误
11-28 16:08:50.168: E/AndroidRuntime(27284): FATAL EXCEPTION: main
11-28 16:08:50.168: E/AndroidRuntime(27284): android.database.sqlite.SQLiteException: near "General": syntax error: , while compiling: SELECT Region,City,Address,Contact FROM tblHospitals WHERE HospitalName = Bernardino General Hospital
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at com.dr.droid.lee.Health.onListItemClick(Health.java:54)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.app.ListActivity$2.onItemClick(ListActivity.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.widget.AbsListView.performItemClick(AbsListView.java:1071)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2527)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.widget.AbsListView$1.run(AbsListView.java:3181)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.os.Handler.handleCallback(Handler.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.os.Handler.dispatchMessage(Handler.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.os.Looper.loop(Looper.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at android.app.ActivityThread.main(ActivityThread.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 16:08:50.168: E/AndroidRuntime(27284): at java.lang.reflect.Method.invoke(Method.java:511)
11-28 16:08:50.168: E/AndroidRuntime(27284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
11-28 16:08:50.168: E/AndroidRuntime(27284): at dalvik.system.NativeStart.main(Native Method)
这是我的课程文件
public class Health extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.health);
displayHospitals();
}
public void displayHospitals (){
final ListView lv = getListView();
DbHelper tblHL = new DbHelper(this);
tblHL.open();
ArrayList<String> result = tblHL.getHData();
result = tblHL.getHData();
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, result));
lv.setTextFilterEnabled(true);
tblHL.close();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String hosp = (String)getListAdapter().getItem(position);
String quer = "SELECT Region,City,Address,Contact FROM tblHospitals WHERE HospitalName = " +hosp ;
SQLiteDatabase mydb = openOrCreateDatabase("dbDrDroid", MODE_PRIVATE, null);
Cursor c = mydb.rawQuery(quer, null);
c.moveToFirst();
Toast.makeText(this, c.toString(), Toast.LENGTH_SHORT).show();
}
}