我已经看到很多话题都在谈论这个问题,例如关于SNAPSHOT版本的这个answer。
这仍然是必要的,因为当我尝试设置我的活动时,我得到:
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
在XML中,声明了fragment
:
<fragment
android:id="@+id/map"
android:tag="mapfragment"
class="com.me.widget.CustomSupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
CustomMapFragment
扩展SupportMapFragment
我的依赖项:
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"
那么我在这里错过了什么?
答案 0 :(得分:2)
我想那里的问题已解决:
https://stackoverflow.com/a/18014423/4370675
此外,在github问题中,我找到了相同的解决方案,它对我有用:
https://github.com/robolectric/robolectric/issues/617#event-61572116
希望你也解决了你的问题。