4

编辑:

ORMLite版本发生错误4.48。我回滚到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我可以很好地导入我的代码。

4

2 回答 2

2

我也发生了同样的情况,感谢您的帮助...当回滚到 4.45 时,问题已解决。

于 2013-11-25T01:29:45.767 回答
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> 
于 2013-12-17T17:06:52.257 回答