Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric 3.0 InflateException with a map custom fragment

I've seen many topic talking about this problem for example this answer concerning the SNAPSHOT version.

Is this still necessary because when I try to setup my activity I get :

    android.view.InflateException: XML file /Users/billey_b/android/android/app/build/intermediates/res/merged/targetARTVm/debug/layout/activity_preorder.xml line #-1 (sorry, not yet implemented): Error inflating class fragment
android.view.InflateException: XML file build/intermediates/res/merged/targetARTVm/debug/layout/activity_preorder.xml line #-1 (sorry, not yet implemented): Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
    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 android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    at com.heetch.activities.PreOrderActivity.onCreate(PreOrderActivity.java:72)
    at android.app.Activity.performCreate(Activity.java:5933)
    at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
    at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
    at org.robolectric.util.ActivityController.create(ActivityController.java:118)
    at org.robolectric.util.ActivityController.create(ActivityController.java:129)
    at org.robolectric.util.ActivityController.setup(ActivityController.java:210)
    at org.robolectric.Robolectric.setupActivity(Robolectric.java:46)
    at com.heetch.flow.preorder.PreOrderSequencesFlowTest.testPreorderFlow(PreOrderSequencesFlowTest.java:40)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
Caused by: java.lang.NullPointerException
    at com.google.android.gms.maps.internal.zzy.zzaR(Unknown Source)
    at com.google.android.gms.maps.internal.zzy.zzaP(Unknown Source)
    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment$zzb.zzzh(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment$zzb.setActivity(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2169)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:842)
    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
    ... 38 more

In the XML the fragment in question is declared :

          <fragment
            android:id="@+id/map"
            android:tag="mapfragment"
            class="com.me.widget.CustomSupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

The CustomMapFragment extends SupportMapFragment

And my dependencies :

testCompile 'org.robolectric:robolectric:3.0'
testCompile "org.robolectric:shadows-play-services:3.0"
testCompile "org.robolectric:shadows-multidex:3.0"
testCompile 'org.robolectric:shadows-maps:3.0'
testCompile "org.robolectric:shadows-support-v4:3.0"

So what I've missed here ?

like image 288
agonist_ Avatar asked Nov 26 '15 08:11

agonist_


1 Answers

I guess the problem is resolved there :

https://stackoverflow.com/a/18014423/4370675

Also, in github issues I found the same solution and it worked for me :

https://github.com/robolectric/robolectric/issues/617#event-61572116

Hope you have solved your problem too.

like image 63
Abhinav Puri Avatar answered Sep 28 '22 19:09

Abhinav Puri