0

when I return to nav_home the application displays an error . What might be happening?

The other buttons are working perfectly , only nav_home is not working.

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

Log

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

This XML is called in my onCreate method located in my ActivityMain and works perfectly . The application calls this Fragment but to change Fragment and return to this XML application shows an error.

XML fragment Main

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

3 Answers3

0

From the error message one can conclude your xml for that fragment is incorrect. Try opening the xml in the AS design editor and see what's wrong.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

according to their error, there is a fault in the xml. Please if you are so kind to add the code to check your xml. regards

AGil
  • 53
  • 6
  • ok you use this xml to load a fragment element. please check the methods and objects that you initialized with this view. You may present problems with onResume () and onPause () and instances. Because if the first charge well and show that mistake again. this could help [activity](http://developer.android.com/intl/es/reference/android/app/Activity.html) please let me know – AGil May 07 '16 at 17:40
0

Try cleaning your project and then `invalidate Caches / Restart/.

and if doesn't help checkout this question

Community
  • 1
  • 1
Atiq
  • 14,435
  • 6
  • 54
  • 69