You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
java.lang.RuntimeException: java.lang.NullPointerException
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at android.content.ContentResolver.addStatusChangeListener(ContentResolver.java:1797)
at a.b.c.XyzApplication.onCreate(XyzApplication.java:45)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:164)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:430)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
... 16 more
The MyApplication.onCreate() method is very simple and looks like this:
@Override
public void onCreate() {
super.onCreate();
// Watch for sync state changes
final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
this.syncObserverHandle = ContentResolver.addStatusChangeListener(mask, this.syncStatusObserver);
}
I guess it has something to do with the getContentService() method returning null:
public static Object addStatusChangeListener(int mask, final SyncStatusObserver callback) {
if (callback == null) {
throw new IllegalArgumentException("you passed in a null callback");
}
try {
ISyncStatusObserver.Stub observer = new ISyncStatusObserver.Stub() {
public void onStatusChanged(int which) throws RemoteException {
callback.onStatusChanged(which);
}
};
getContentService().addStatusChangeListener(mask, observer);
return observer;
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
Running this code on a device or emulator is fine but running in Robolectric results in a NullPointerException.
Is the ContentService not yet available in Application.onCreate()?
The text was updated successfully, but these errors were encountered:
Please test it with latest Robolectric again to verify whether it fixes this issue. The Robolectric version related to this issue is too old. If this issue still exits with latest Robolectric 4.9, feel free to reopen this issue and attach a minimal reproducable app that we can use to reproduce this issue and for later investigation. Thanks.
The MyApplication.onCreate() method is very simple and looks like this:
I guess it has something to do with the getContentService() method returning null:
Running this code on a device or emulator is fine but running in Robolectric results in a NullPointerException.
Is the ContentService not yet available in Application.onCreate()?
The text was updated successfully, but these errors were encountered: