所以最近我正在尝试测试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'
}
有人帮我吗?
谢谢 :)
附言:这是
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;
}
}
最佳答案
下一个AndroidX版本的Room将解决此问题。
资料来源:https://issuetracker.google.com/issues/110100403
关于android - 应用程序因WorkManager崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50888907/