{"id":8137,"date":"2015-11-28T04:15:08","date_gmt":"2015-11-28T04:15:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/28\/npe-when-getting-robolectric-shadowapplication-with-volley-and-dagger-open-source-projects-square-dagger\/"},"modified":"2022-08-30T15:03:00","modified_gmt":"2022-08-30T15:03:00","slug":"npe-when-getting-robolectric-shadowapplication-with-volley-and-dagger-open-source-projects-square-dagger","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/28\/npe-when-getting-robolectric-shadowapplication-with-volley-and-dagger-open-source-projects-square-dagger\/","title":{"rendered":"NPE when getting Robolectric ShadowApplication with Volley and Dagger-open source projects square\/dagger"},"content":{"rendered":"<p>In my Android application I have set up Volley.<\/p>\n<p>Robolectric.application is initialized and all other tests runs smoothly. I get this error when trying to get mocked HTTP response.<\/p>\n<p>This is my test:<\/p>\n<pre><code>@RunWith(MyRobolectricTestRunner.class)\npublic class ApiTests {\n\n    @Inject\n    protected Api api;\n\n    @Before\n    public void setUp() {\n        ObjectGraph.create(new AndroidModule(Robolectric.application), new TestApplicationModule()).inject(this);\n    }\n\n    @Test\n    public void shouldGetErrorList() throws Exception {\n        Project project = new Project(\"test\", \"test\", \"test\", DateTime.now());\n        addPendingProjectsErrorsResponse(\"response.json\"); \/\/adding response to FakeHttpLayer\n\n        api.getProjectErrors(project, new Listener() {\n                @Override\n                public void onResponse(ProjectErrors response) {\n                    assertNotNull(response);\n                }\n            }, new ErrorListener() {\n                @Override\n                public void onErrorResponse(VolleyError error) {\n                    throw new RuntimeException(error);\n                }\n            }\n        );\n    }\n}\n<\/code><\/pre>\n<p>This is error I get:<\/p>\n<pre><code>Exception in thread \"Thread-3\" java.lang.NullPointerException\n    at org.robolectric.shadows.ShadowLooper.getMainLooper(ShadowLooper.java:59)\n    at android.os.Looper.getMainLooper(Looper.java)\n    at org.robolectric.Robolectric.getUiThreadScheduler(Robolectric.java:1301)\n    at org.robolectric.shadows.ShadowSystemClock.now(ShadowSystemClock.java:15)\n    at org.robolectric.shadows.ShadowSystemClock.uptimeMillis(ShadowSystemClock.java:25)\n    at org.robolectric.shadows.ShadowSystemClock.elapsedRealtime(ShadowSystemClock.java:30)\n    at android.os.SystemClock.elapsedRealtime(SystemClock.java)\n    at com.android.volley.VolleyLog$MarkerLog.add(VolleyLog.java:114)\n    at com.android.volley.Request.addMarker(Request.java:174)\n    at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:92)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In my Android application I have set up Volley. Robolectric.application is initialized and all other tests runs smoothly. I get this error when trying to get mocked HTTP response. This is my test: @RunWith(MyRobolectricTestRunner.class) public class ApiTests { @Inject protected Api api; @Before public void setUp() { ObjectGraph.create(new AndroidModule(Robolectric.application), new TestApplicationModule()).inject(this); } @Test public void [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8137","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8137"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8137\/revisions"}],"predecessor-version":[{"id":8590,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8137\/revisions\/8590"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}