2016-05-07 23 views
0

應用程序顯示錯誤。可能發生了什麼?當我返回到nav_home時,返回主片段

其他按鈕工作正常,只有nav_home不工作。

public boolean onNavigationItemSelected(MenuItem item) { 
      FragmentManager fm = getFragmentManager(); 
      int id = item.getItemId(); 

      if (id == R.id.nav_home) { 
       fm.beginTransaction().replace(R.id.content_frame, new MainFragment()).commit(); 
      } else if (id == R.id.nav_perfil) { 
       fm.beginTransaction().replace(R.id.content_frame, new Perfil()).commit(); 
      }else if (id == R.id.nav_cadprof) { 
       fm.beginTransaction().replace(R.id.content_frame, new CadProfFragment()).commit(); 
      } else if (id == R.id.nav_tabelapreco) { 
       fm.beginTransaction().replace(R.id.content_frame, new TabelaPreco()).commit(); 

      } else if (id == R.id.nav_ajuda) { 
       fm.beginTransaction().replace(R.id.content_frame, new Ajuda()).commit(); 

      } else if (id == R.id.nav_sobre) { 
       fm.beginTransaction().replace(R.id.content_frame, new Sobre()).commit(); 

      } else if (id == R.id.nav_slogan) { 

      } 

      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
      drawer.closeDrawer(GravityCompat.START); 
      return true; 
     } 
    } 

登錄

05-07 12:54:25.364 27082-27082/com.caseb.case_beauty_ E/AndroidRuntime: FATAL EXCEPTION: main 
                     Process: com.caseb.case_beauty_, PID: 27082 
                     android.view.InflateException: Binary XML file line #18: Error inflating class fragment 

這個XML被稱爲在我位於我ActivityMain onCreate方法和完美的作品。應用程序調用這個Fragment,但改變Fragment並返回到這個XML應用程序顯示一個錯誤。主要

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.caseb.case_beauty_Fargments.MainFragment"> 

    <!-- TODO: Update blank fragment layout --> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/map" 
     android:orientation="vertical"> 

     <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:map="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/map" 
      android:name="com.google.android.gms.maps.SupportMapFragment" 
      android:layout_width="fill_parent" 
      android:layout_height="300dp" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentStart="true" 
      tools:context="com.caseb.testemaps.MapsActivity" 
      tools:layout="@layout/content_main" /> 

     <Button 
      android:id="@+id/bt_estimavalor" 
      android:layout_width="129dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@drawable/screen_border" 
      android:backgroundTint="#66e72bac" 
      android:text="Estimar Valor" 
      android:textColor="#ffffff" /> 

     <Button 
      android:id="@+id/bt_enviasolicita" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="16dp" 
      android:background="@drawable/screen_border" 
      android:backgroundTint="#66e72bac" 
      android:text="Enviar Localização e Solicitar" 
      android:textColor="#ffffff" 
      android:textStyle="bold" /> 

     <ExpandableListView 
      android:id="@+id/expandableListView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 


</FrameLayout> 

回答

0

從錯誤信息

XML片段可以斷定你的XML該片斷是不正確。嘗試在AS設計編輯器中打開xml,看看有什麼不對。

+0

XML,千萬不要以爲這是出了問題。 –

0

根據它們的錯誤,在xml中存在錯誤。如果你是如此友善地添加代碼來檢查你的xml。問候

+0

添加到描述,謝謝你的幫助。 –

+0

好的,你使用這個XML加載一個片段元素。請檢查使用此視圖初始化的方法和對象。你可能會出現onResume()和onPause()和實例的問題。因爲如果第一次充電並再次出現錯誤。這可以幫助[活動](http://developer.android.com/intl/es/reference/android/app/Activity.html)請讓我知道 – UclidesGil

0

嘗試清理你的項目,然後`無效緩存/重啓/。

,如果不幫助結帳在描述這個question