0
我有一個應用程序試圖讀取位於外部卡上的數據庫。重點在於數據庫打開是因爲它警告我Toast,但我無法使用表名的字段數據加載遊標。數據庫被稱爲bas schedule,在它內部有一個表llamda與一個名爲name的列聯繫。我使用的代碼如下: 嘗試{創建位於外部SD卡上的光標數據庫
SQLiteDatabase.openDatabase("/storage/external_SD/.Sistem/agenda", null, SQLiteDatabase.OPEN_READWRITE);
Toast.makeText(this, "BD1 abierta", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(this, "No se pudo abrir BD1", Toast.LENGTH_LONG).show();
}
try {
Spinner spn2 = (Spinner)this.findViewById(R.id.spn2);
Cursor cur1 = baseDatos.rawQuery("select nombre from contactos ORDER BY nombre ASC", null);
startManagingCursor(cur1);
String[] from = new String[]{"nombre"};
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, cur1, from, to);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spn2.setAdapter(mAdapter);
} catch (Exception e) {
Log.i(TAG, "Error al abrir o crear la base de datos" + e);
}
謝謝。