リストビューでクリックされたアイテムに一致する特定のフィールドをデータベースから選択しようとしています。アプリを実行してアイテムをクリックすると、アプリがクラッシュします。コードの何が問題になっていますか?
これが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();
}
}