[英]Class SpringHibernateJpaPersistenceProvider does not implement the requested interface PersistenceProvider
[英]SQLiteDatabase 'does not implement interface'
使用SQLiteDatabase作為Closeable時出現此錯誤
我有一個示例項目來重新創建它:
https://github.com/blundell/SQLDatabaseError
使用擴展SQLiteOpenHelper的類:
public class DatabaseHelper extends SQLiteOpenHelper {
....
public void openAndCloseDatabase() {
SQLiteDatabase database = getWritableDatabase();
close(database);
}
private void close(Closeable database) {
try {
if (database != null) {
database.close();
}
} catch (Exception e) {
Log.e("Error", "Oh no!", e);
}
}
}
堆棧跟蹤:
12-14 12:23:43.719: E/AndroidRuntime(5179): FATAL EXCEPTION: main
12-14 12:23:43.719: E/AndroidRuntime(5179): java.lang.IncompatibleClassChangeError: interface not implemented
12-14 12:23:43.719: E/AndroidRuntime(5179): at com.blundell.sqldatabasecursorerror.DatabaseHelper.close(DatabaseHelper.java:35)
12-14 12:23:43.719: E/AndroidRuntime(5179): at com.blundell.sqldatabasecursorerror.DatabaseHelper.openAndCloseDatabase(DatabaseHelper.java:29)
12-14 12:23:43.719: E/AndroidRuntime(5179): at com.blundell.sqldatabasecursorerror.MainActivity.onCreate(MainActivity.java:13)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.os.Looper.loop(Looper.java:130)
12-14 12:23:43.719: E/AndroidRuntime(5179): at android.app.ActivityThread.main(ActivityThread.java:3701)
12-14 12:23:43.719: E/AndroidRuntime(5179): at java.lang.reflect.Method.invokeNative(Native Method)
12-14 12:23:43.719: E/AndroidRuntime(5179): at java.lang.reflect.Method.invoke(Method.java:507)
12-14 12:23:43.719: E/AndroidRuntime(5179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
12-14 12:23:43.719: E/AndroidRuntime(5179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
12-14 12:23:43.719: E/AndroidRuntime(5179): at dalvik.system.NativeStart.main(Native Method)
API:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
http://developer.android.com/reference/android/database/sqlite/SQLiteClosable.html
http://developer.android.com/reference/java/io/Closeable.html
這應該工作不應該嗎?
public final class SQLiteDatabase extends SQLiteClosable
>>
public abstract class SQLiteClosable extends Object implements Closeable
>>
public interface Closeable
不起作用:
工作:
好的, 在4.1的更改說明(API級別16)中發現了問題:
android.database.sqlite.SQLiteClosable
僅從API級別16實現java.io.Closeable
。在此之前,它們是無關的(即使兩個接口從一開始就存在)。
因此,如果您希望代碼向后兼容,則應直接使用SQLiteClosable。
也可能值得為您想要支持的最低版本安裝SDK並嘗試使用它構建,然后編譯器會檢測到這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.