Caused by: android.database.sqlite.SQLiteException: near "xxxx"

时间:2022-05-09 01:12:42
</pre>先看错误:<pre name="code" class="plain">08-16 11:06:31.221: E/AndroidRuntime(12581): Caused by: android.database.sqlite.SQLiteException: near "ID": syntax error (code 1): , while compiling: SELECT * FROM cart c 

INNER JOIN food f ON c.foodID=f.food ID
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at com.xxx.xxxxx.xxxxx.xxx.query(CartProvider.java:35)(应用包名)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.content.ContentProvider.query(ContentProvider.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.content.ContentProvider$Transport.query(ContentProvider.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.content.ContentResolver.query(ContentResolver.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.content.ContentResolver.query(ContentResolver.java)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:240)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-16 11:06:31.221: E/AndroidRuntime(12581): 	... 3 more


出现这种错误,一般都是SQL语句拼写错误,或者使用androidApi的使用错误,仔细检查一下一的sql语法是否错误.

请看我的错误:

Caused by: android.database.sqlite.SQLiteException: near "xxxx"


很明显 foodID有一个空格,错误就在这里.