i guess you're using an incompatible robolectric and android sdk versions:

with robolectric 3, you should use :

myactivity activity = robolectric.setupactivity(myactivity.class);


i’m using android studio 3.1.1 and also got a nullpointerexception when calling robolectric.buildactivity(…).create().get(). then i found the following link:

where it is recommended to add the following block to your app’s build.gradle file:

android {
    testoptions {
        unittests { 
            includeandroidresources = true 

with this addition the exception was avoided. i’m not sure if this solution works for your case. just sharing.

Related Query

More Query from same tag