Ошибка SQL (запроса) или отсутствует база данных.(нет такой таблицы: TABLE_NAME (код 1): при компиляции: SELECT * FROM TABLE_NAME WHERE IDNO = idNo
)
Когда я звоню insertData()
, приложение вылетает, показывая следующую ошибку:
Caused by: android.database.sqlite.SQLiteException: no such table:
TABLE_NAME (code 1): , while compiling: SELECT * FROM TABLE_NAME
WHERE IDNO = idNo
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(no such table: TABLE_NAME (code 1): , while compiling: SELECT * FROM TABLE_NAME WHERE IDNO = idNo)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1073)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:638)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1722)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1661)
at my.utar.phonesecurity.DatabaseHelper.getData(DatabaseHelper.java:91)
at my.utar.phonesecurity.BaseProfilingActivity.checkDatabase(BaseProfilingActivity.java:266)
at my.utar.phonesecurity.BaseProfilingActivity.onCreate(BaseProfilingActivity.java:116)
at android.app.Activity.performCreate(Activity.java:6977)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
, пожалуйста, см.какая в этом ошибка.чтобы он мог нормально работать.
package my.utar.phonesecurity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "data.db";
private static final String TABLE_NAME = "screenGestures";
Context context;
String[] deleteString = {"ID", "USER", "LENGTH", "ABSOLUTELENGTH", "DURATION", "AVGSPEED", "STARTPRESSURE", "ENDPRESSURE", "AVGPRESSURE",
"STARTSIZE", "ENDSIZE", "AVGSIZE", "STARTX", "STARTY", "ENDX", "ENDY", "DIRECTION", "AREA", "MOVETYPE", "USERID",
"TRORTST", "CRATEDAT", "MOBILEMODELNO"};
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
this.context = context;
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + "(IDNO INTEGER PRIMARY KEY AUTOINCREMENT,ID TEXT,USER TEXT, LENGTH TEXT, ABSOLUTELENGTH TEXT, " +
"DURATION TEXT, AVGSPEED TEXT, STARTPRESSURE TEXT, ENDPRESSURE TEXT, AVGPRESSURE TEXT, STARTSIZE TEXT, ENDSIZE TEXT, " +
" AVGSIZE TEXT, STARTX TEXT, STARTY TEXT, ENDX TEXT, ENDY TEXT,DIRECTION TEXT, AREA TEXT, MOVETYPE TEXT, USERID TEXT ," +
"TRORTST TEXT , CRATEDAT TEXT ,MOBILEMODELNO TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public boolean insertData(String id, String user, String length, String absoluteLength, String duration, String avgSpeed,
String startPressure, String endPressure, String avgPressure, String startSize, String endSize,
String avgSize, String startX, String startY, String endX, String endY, String direction,
String area, String moveType, String userId, String trOrTst, String cratedAt, String mobileModelNo) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("ID", id);
contentValues.put("USER", user);
contentValues.put("LENGTH", length);
contentValues.put("ABSOLUTELENGTH", absoluteLength);
contentValues.put("DURATION", duration);`4`
contentValues.put("AVGSPEED", avgSpeed);
contentValues.put("STARTPRESSURE", startPressure);
contentValues.put("ENDPRESSURE", endPressure);
contentValues.put("AVGPRESSURE", avgPressure);
contentValues.put("STARTSIZE", startSize);
contentValues.put("ENDSIZE", endSize);
contentValues.put("AVGSIZE", avgSize);
contentValues.put("STARTX", startX);
contentValues.put("STARTY", startY);
contentValues.put("ENDX", endX);
contentValues.put("ENDY", endY);
contentValues.put("DIRECTION", direction);
contentValues.put("AREA", area);
contentValues.put("MOVETYPE", moveType);
contentValues.put("USERID", userId);
contentValues.put("TRORTST", trOrTst);
contentValues.put("CREATEDAT", cratedAt);
contentValues.put("MOBILEMODEL", mobileModelNo);
if (db.insert(TABLE_NAME, null, contentValues) == -1) {
return false;
}
return true;
}
public int deleteData(int idNo) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME, "IDNO = ?", new String[]{String.valueOf(idNo)});
/*if (result == -1) {
return false;
} else {
return true;
}*/
}
public Cursor getData(int idNo) {
SQLiteDatabase db = this.getWritableDatabase();
String query = " SELECT * FROM TABLE_NAME WHERE IDNO = idNo";
/*String query = "SELECT * FROM " + TABLE_NAME;*/
Cursor cursor = db.rawQuery(query, null);
return cursor;
}
public long getSize() {
SQLiteDatabase db = this.getReadableDatabase();
int size = (int) db.getPageSize();
long sizee = new File(db.getPath()).length();
return size;
}
}