2013-10-24 58 views
4

編輯:導入android.os.CancellationSignal不能在Android上得到解決ORMLite

誤差與4.48ORMLite版本出現。我回滾到4.45並且錯誤停止發生。


我實現了使用ORMLite爲Android在網站上方向下的數據庫。但是,任何時候我嘗試寫到數據庫中,我得到一個異常:

10-24 15:15:04.600: E/AndroidRuntime(12057): FATAL EXCEPTION: IntentService[com.mypackage.instagram.UpdateInstagramPhotosService] 
10-24 15:15:04.600: E/AndroidRuntime(12057): java.lang.ExceptionInInitializerError 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.android.AndroidDatabaseConnection.compileStatement(AndroidDatabaseConnection.java:146) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:460) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.table.TableUtils.doCreateTable(TableUtils.java:443) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:220) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:53) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.mypackage.database.DatabaseHelper.onCreate(DatabaseHelper.java:33) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.onCreate(OrmLiteSqliteOpenHelper.java:209) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:66) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:306) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.mypackage.instagram.UpdateInstagramPhotosService.performUpdate(UpdateInstagramPhotosService.java:85) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.mypackage.PhotoUpdateService.onHandleIntent(PhotoUpdateService.java:27) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at android.os.Handler.dispatchMessage(Handler.java:99) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at android.os.Looper.loop(Looper.java:137) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at android.os.HandlerThread.run(HandlerThread.java:60) 
10-24 15:15:04.600: E/AndroidRuntime(12057): Caused by: java.lang.ExceptionInInitializerError 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.android.AndroidCompiledStatement.<clinit>(AndroidCompiledStatement.java:33) 
10-24 15:15:04.600: E/AndroidRuntime(12057): ... 17 more 
10-24 15:15:04.600: E/AndroidRuntime(12057): Caused by: java.lang.Error: Unresolved compilation problems: 
10-24 15:15:04.600: E/AndroidRuntime(12057): The import android.os.CancellationSignal cannot be resolved 
10-24 15:15:04.600: E/AndroidRuntime(12057): CancellationSignal cannot be resolved to a type 
10-24 15:15:04.600: E/AndroidRuntime(12057): CancellationSignal cannot be resolved to a type 
10-24 15:15:04.600: E/AndroidRuntime(12057): CancellationSignal cannot be resolved to a type 
10-24 15:15:04.600: E/AndroidRuntime(12057): CancellationSignal cannot be resolved to a type 
10-24 15:15:04.600: E/AndroidRuntime(12057): CancellationSignal cannot be resolved to a type 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.android.compat.JellyBeanApiCompatibility.<init>(JellyBeanApiCompatibility.java:5) 
10-24 15:15:04.600: E/AndroidRuntime(12057): at com.j256.ormlite.android.compat.ApiCompatibilityUtils.<clinit>(ApiCompatibilityUtils.java:40) 
10-24 15:15:04.600: E/AndroidRuntime(12057): ... 18 more 

這是在IntentService子發生。以下是該類的一些相關代碼:

private DatabaseHelper databaseHelper; 
static { 
    OpenHelperManager.setOpenHelperClass(DatabaseHelper.class); 
} 

public DatabaseHelper getHelper() { 
    if (databaseHelper == null) { 
     databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class); 
    } 
    return databaseHelper; 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 

    if (databaseHelper != null) { 
     OpenHelperManager.releaseHelper(); 
     databaseHelper = null; 
    } 
} 

我可以在我的代碼中導入android.os.CancellationSignal就好了。

+2

我與版本4.48有同樣的問題。 – koso

+1

謝謝你的同樣的問題而且我swings更低的版本 – topxebec

+1

我也遇到過這樣的崩潰。剛剛切換到4.47,現在一切正常 – Robert

回答

2

這與我一樣,感謝您的幫助......當回滾到4.45時,問題解決了。

+0

感謝您的回答! – friddle

1

導入android.os.CancellationSignal不能在Android

這是發生在ORMLite源的主幹版本來解決ORMLite。 4.48添加了Android兼容性層的第一個開始(不幸的是)這意味着有些類不能在早期版本的Android API下編譯。

這就是說,我忘記了升級適當版本的Android API的pom.xml文件。 4.48版本做出了以下改變,這對你的工作應該很好。

<!-- <android-version>2.3.3</android-version> --> 
<android-version>4.1.1.4</android-version> 
相關問題