所以最近我试图测试WorkManager并且我有一个我不知道如何解决它的错误...
我遇到的错误就是这个:
2018-06-16 16:36:36.594 23798-23815/? E/AndroidRuntime: FATAL EXCEPTION: pool-2-thread-1
Process: com.example.damiii.myjobintentservice, PID: 23798
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:135)
at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:116)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:150)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:409)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:97)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:55)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:253)
at androidx.work.impl.utils.EnqueueRunnable.addToDatabase(EnqueueRunnable.java:93)
at androidx.work.impl.utils.EnqueueRunnable.run(EnqueueRunnable.java:79)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
我查看了我可能遇到此错误的位置,而且当我对该代码发表评论时,似乎是这样:
//WorkRequest can be customised for backoff criteria
OneTimeWorkRequest checkOfflineNetworkState = new OneTimeWorkRequest.Builder(NoNetworkWorker.class).setConstraints(mConstraints).build();
WorkManager.getInstance().enqueue(checkOfflineNetworkState);
我的应用效果很好......
我不知道问题是来自WorkManager
还是来自我所做的实施......
这是我项目的信息:
minSDKversion : 14
targetSDKversion : 28
我的gradle.build
:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
// implementation "com.android.support:appcompat-v7:28.0.0"
// implementation 'com.android.support:support-v4:28.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha3'
implementation "android.arch.work:work-runtime:1.0.0-alpha02"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}
有人帮我吗? 谢谢你:))
P.S。:这是来自NoNetworkWorker
的代码:
package com.example.damiii.myjobintentservice;
import android.util.Log;
import androidx.work.Worker;
public class NoNetworkWorker extends Worker {
/**
* Override this method to do your actual background processing.
*
* @return The result of the work, corresponding to a {@link WorkerResult} value. If a
* different value is returned, the result shall be defaulted to
* {@link WorkerResult#FAILURE}.
*/
@Override
public WorkerResult doWork() {
Log.d("Hello", "I'm offline :D");
return WorkerResult.SUCCESS;
}
}
答案 0 :(得分:2)
此问题将通过下一个AndroidX版本的Room修复。
答案 1 :(得分:1)
更新到WorkManager 1.0.0-alpha03