我真的很难弄清楚这个奇怪的问题。在我的Android应用程序中,我有一个包含支持地图片段的片段。当GPS打开时,谷歌地图工作正常,这个片段创建很好。但是当GPS关闭时,应用程序甚至无法实例化,它只是在打开它时崩溃。
这是堆栈跟踪:
07-31 22:35:47.905: E/AndroidRuntime(32324): FATAL EXCEPTION: main
07-31 22:35:47.905: E/AndroidRuntime(32324): android.view.InflateException: Binary XML file line #9: Error inflating class fragment
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-31 22:35:47.905: E/AndroidRuntime(32324): at au.net.gokart.fragments.TrackInfoFragment.onCreateView(TrackInfoFragment.java:69)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.View.measure(View.java:15524)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5109)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.View.measure(View.java:15524)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5109)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.View.measure(View.java:15524)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.View.measure(View.java:15524)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5109)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-31 22:35:47.905: E/AndroidRuntime(32324): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.View.measure(View.java:15524)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1986)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1227)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1400)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1120)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4604)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.os.Handler.handleCallback(Handler.java:615)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.os.Looper.loop(Looper.java:137)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.app.ActivityThread.main(ActivityThread.java:4921)
07-31 22:35:47.905: E/AndroidRuntime(32324): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 22:35:47.905: E/AndroidRuntime(32324): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 22:35:47.905: E/AndroidRuntime(32324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-31 22:35:47.905: E/AndroidRuntime(32324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-31 22:35:47.905: E/AndroidRuntime(32324): at dalvik.system.NativeStart.main(Native Method)
07-31 22:35:47.905: E/AndroidRuntime(32324): Caused by: java.lang.IllegalStateException: Fragment com.google.android.gms.maps.SupportMapFragment did not create a view.
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:308)
07-31 22:35:47.905: E/AndroidRuntime(32324): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
07-31 22:35:47.905: E/AndroidRuntime(32324): ... 46 more
这是我的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
class="com.google.android.gms.maps.SupportMapFragment"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiTiltGestures="true"
map:uiZoomControls="true"
map:uiZoomGestures="true" />
</LinearLayout>
这是我的片段onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
this.activity = this.getActivity();
ActionBar ab = getActivity().getActionBar();
if (ab.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD) {
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
ab.setDisplayHomeAsUpEnabled(false);
checkForGooglePlayServices();
View view = inflater.inflate(R.layout.fragment_trackinfo, container, false);
setUpMapIfNeeded();
return view;
}
非常感谢任何帮助