我需要從手機內存(/ storage/emulated/0)打開一個數據庫,並且打開的數據庫(由Linux的DB瀏覽器創建)的「SQLiteCantOpenDatabaseException」有表「android_metadata」和他們各自的字段(locale ... es_US)。打開數據庫Android
我需要開放,從外部數據庫中讀取數據(應用程序需要從網站上下載的數據庫和讀取數據,並把中的TextView到應用程序的活動)
該應用程序有權讀取和寫入外部存儲器下面
代碼(僅按鈕的代碼來獲取數據庫的引用)
case R.id.button4:
{
int ID,IDn,IDa;
String cabeceras[] ={"nombre","apellido",_ID},lectura=new String(),err="";
ArrayList<String> arregloDatos = new ArrayList<>();
try {
SQLiteDatabase db = SQLiteDatabase.openDatabase(Environment.getExternalStorageDirectory().getPath() +"/"+"pruebaDB.db", null, SQLiteDatabase.OPEN_READWRITE);
Cursor cursor = db.query("persona", cabeceras, null, null, null, null, null);
ID = cursor.getColumnIndex(_ID);
IDn = cursor.getColumnIndex("nombre");
IDa = cursor.getColumnIndex("apellido");
while (cursor.moveToNext()) {
lectura = cursor.getString(ID) + " " + cursor.getString(IDn) + " " + cursor.getString(IDa);
arregloDatos.add(lectura);
}
Intent i = new Intent(this, Main2Activity.class);
i.putStringArrayListExtra("cadena", arregloDatos);
startActivity(i);
}catch (Exception g)
{
Toast msg =Toast.makeText(this,g.getClass().toString(),Toast.LENGTH_SHORT);
msg.show();
}
break;
}
編輯:我發現這個問題,這個問題是光標,becose我評論它,應用程序沒有顯示出任何異常。 現在...我的問題是「如何從SQliteDatabase對象讀取數據」
確定您的數據庫路徑正確嗎? – gdaras
是的,y從Toast中讀取並獲得「/ storage/emulated/0」並檢查文件是否存在我的文件資源管理器 –