LocationPickerActivity is showing MapboxConfigurationException while creating it in a test class
See original GitHub issueDescription
I was trying to add tests for the LocationPickerActivity class. But getting errors while building the class. Can’t find any solution for that.
What I was doing
Error
Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class com.mapbox.mapboxsdk.maps.MapView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at fr.free.nrw.commons.LocationPicker.LocationPickerActivity.onCreate(LocationPickerActivity.java:139)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:730)
at org.robolectric.android.controller.ActivityController.lambda$create$0(ActivityController.java:106)
at org.robolectric.shadows.ShadowPausedLooper.runPaused(ShadowPausedLooper.java:200)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:106)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:111)
at fr.free.nrw.commons.locationpicker.LocationPickerActivityUnitTests.setUp(LocationPickerActivityUnitTests.kt:32)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:568)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:365)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at fr.free.nrw.commons.LocationPicker.LocationPickerActivity.onCreate(LocationPickerActivity.java:139)
at android.app.Activity.$$robo$$android_app_Activity$performCreate(Activity.java:5933)
at android.app.Activity.performCreate(Activity.java)
at android.app.Instrumentation.$$robo$$android_app_Instrumentation$callActivityOnCreate(Instrumentation.java:1105)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:730)
at org.robolectric.android.controller.ActivityController.lambda$create$0(ActivityController.java:106)
at org.robolectric.shadows.ShadowPausedLooper.runPaused(ShadowPausedLooper.java:200)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:106)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:111)
at fr.free.nrw.commons.locationpicker.LocationPickerActivityUnitTests.setUp(LocationPickerActivityUnitTests.kt:32)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
Caused by: com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException:
Using MapView requires calling Mapbox.getInstance(Context context, String accessToken) before inflating or creating the view. The access token parameter is required when using a Mapbox service.
Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
at com.mapbox.mapboxsdk.maps.MapView.initialize(MapView.java:132)
at com.mapbox.mapboxsdk.maps.MapView.<init>(MapView.java:108)
I think the exception is occurring because of using Mapview and it’s asking for this Mapbox.getInstance(Context context, String accessToken)
. But NearbyParentFragment also is using mapview in the same way, it’s not giving error while inflating the layout in the test.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Empty test suite when running unit tests in Android Studio
When I created the Instrumented Unit Test I got the error. ... Click on Apply/Ok. Then I right click on the class name,...
Read more >Instrumented Tests - CommonsWare
When you run a test method or a test class, rather than focusing on the output in the emulator or device, you will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@madhurgupta10 That’s great. Sure I will add instrumentation tests too. However, I created unit tests for the class covering as much as possible.
Thanks a lot for the help.
Yes, for now, you can skip onCreate and write tests for other methods