의 지침에 따라 Android 데이터베이스에 기존 SQLite 데이터베이스를 도입했습니다.SQLite 테이블이 존재하지 않습니다. 기존 SQLite 데이터베이스 (및 테이블)의 예외입니다.
"android_metadata"테이블을 쿼리 할 때 괜찮습니다. 하지만 내 자신의 테이블 "단어"(기본 정수 키에 대한 _id가 있음)에 비슷한 쿼리를 실행하면 테이블이 예외가 발생하지 않고 응용 프로그램이 중단됩니다.
왜 그럴까요?
코드 :
Cursor c = myDatabase.query("android_metadata", null, null, null, null, null, null, null);
작동하지만
Cursor c = myDatabase.query("words", null, null, null, null, null, null, null);
테이블은 예외가 존재하지 않습니다 반환합니다.
나는 데이터베이스 (경로 및 파일 이름에 대한 참조가 올바른지) 만드는거야 방법이 있습니다 :
private void copyDatabase() throws IOException
{
//Open local db as the input stream
InputStream myInput = mContext.getAssets().open(DB_NAME);
//Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length = 0;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
(참고 :. 내 눈을, 테이블은 내가 그것을 바로 찾고있다 내 SQLite 브라우저에서)
아무도 거 몇 가지 코드없이 대답 할 수 없다 ... – tobyodavies
을 그렇지 않은 코딩 문제 - 하나의 테이블을 찾을 수 있고 다른 테이블을 찾을 수 없다면 sqlite 데이터베이스가 안드로이드에 맞게 편집 된 방법과 관련된 문제입니다. 나는 누군가가 이것을보아야 만했음을 확신합니다 ... – SK9
더 많은 코드는 "여기"링크를 참조하십시오. 그것은 꽤 표준 SQLiteDatabase 헬퍼 물건입니다. – SK9