我有这个问题:
public void createElement(T e) {
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues values = new ContentValues();
Log.e("path", db.getPath());
}
private String getCreationString() {
List<String> fields = getFields();
String createString = "create table if not exists "
+ getTableName()
+ " ( " ;
for (String field : fields) {
createString = createString+ " " +field +" text "+ ",";
}
if (createString.length() > 0 && createString.charAt(createString.length()-1)==',') {
createString = createString.substring(0, createString.length()-1);
}
createString=createString+ " );";
return createString;
}
public void onCreate(SQLiteDatabase database) {
//dropdatabase(database);
database.execSQL(getCreationString());
}
> 12-02 10:54:37.991: E/SQLiteLog(22945): (1) near "null": syntax error
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): Error inserting 12-02
> 10:54:38.011: E/SQLiteDatabase(22945):
> android.database.sqlite.SQLiteException: near "null": syntax error
> (code 1): , while compiling: INSERT INTO mandat(null) VALUES (NULL)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
> Method) 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> com.facilogi.transellis.database.TransellisTable.createElement(TransellisTable.java:77)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> com.facilogi.transellis.backgroundTasks.BiensWebServiceTask.parse(BiensWebServiceTask.java:40)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> com.facilogi.transellis.backgroundTasks.BiensWebServiceTask.parse(BiensWebServiceTask.java:1)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> com.facilogi.transellis.backgroundTasks.Taskellis.doInBackground(Taskellis.java:132)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> com.facilogi.transellis.backgroundTasks.Taskellis.doInBackground(Taskellis.java:1)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> com.novoda.imageloader.core.loader.util.AsyncTask$2.call(AsyncTask.java:200)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> java.util.concurrent.FutureTask.run(FutureTask.java:234) 12-02
> 10:54:38.011: E/SQLiteDatabase(22945): at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
> 12-02 10:54:38.011: E/SQLiteDatabase(22945): at
> java.lang.Thread.run(Thread.java:841)
中提出的例外情况
ContentValues values = new ContentValues();
我不相信这就是原因 我真的不知道是什么原因可以得到任何帮助 提前谢谢。
答案 0 :(得分:0)
INSERT INTO mandat(null) VALUES (NULL)
您忘了在ContentValues
中添加任何值。
答案 1 :(得分:-2)
在致电SQLiteDatabase db = helper.getWritableDatabase();
你应该初始化SqliteOpenHelper
应执行dbHelper = new DatabaseAdapter(context);
之类的声明。
否则您的数据库将无法打开。