2013-07-31 58 views
1

我真的很難找出這個奇怪的問題。在我的android應用程序中,我有一個包含支持地圖片段的片段。谷歌地圖工作正常,當GPS打開,這個片段創建罰款。但是,當GPS關閉時,應用程序甚至不會實例化,它只會在打開時崩潰。Android SupportMapFragment沒有創建視圖錯誤

這裏是堆棧跟蹤:

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; 
} 

任何幫助將不勝感激

+0

在308行寫什麼? –

+0

這是來自SDK。 FragmentActivity不是我的課程 – Jarrod

回答

0

由於this answer,我設法解決了這個問題。

您需要在您的佈局XML來改變fragment關鍵字FrameLayout