0

My Android app is presenting this error when users re-open the app. The first time the app opens normally. It just happen in some devices (sometimes) and I`m not able to solve it. There are some questions about it here in Stackoverflow, but none of them were answered correctly for me.

Here is the full error from Firebase crash:

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{[REDACTED_DOMAIN_NAME]/com.app.Activities.Activities.PrincipalActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2434)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2494)
android.app.ActivityThread.access$900 (ActivityThread.java:153)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1347)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5451)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)


Caused by android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class fragment
android.view.LayoutInflater.inflate (LayoutInflater.java:539)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
android.view.LayoutInflater.inflate (LayoutInflater.java:374)
com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:393)
android.app.Activity.setContentView (Activity.java:2215)
comwe.app.Activities.Activities.PrincipalActivity.onCreate (PrincipalActivity.java:60)
android.app.Activity.performCreate (Activity.java:6323)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1108)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2387)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2494)
android.app.ActivityThread.access$900 (ActivityThread.java:153)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1347)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5451)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

Caused by android.view.InflateException: Binary XML file line #11: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:782)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704)
android.view.LayoutInflater.rInflate (LayoutInflater.java:835)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
android.view.LayoutInflater.inflate (LayoutInflater.java:515)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
android.view.LayoutInflater.inflate (LayoutInflater.java:374)
com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:393)
android.app.Activity.setContentView (Activity.java:2215)
com.app.Activities.Activities.PrincipalActivity.onCreate (PrincipalActivity.java:60)
android.app.Activity.performCreate (Activity.java:6323)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1108)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2387)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2494)
android.app.ActivityThread.access$900 (ActivityThread.java:153)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1347)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5451)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)


Caused by java.lang.IllegalStateException: Fragment com.app.Activities.Activities.EmptyFragment did not create a view.
android.support.v4.app.FragmentManagerImpl.onCreateView (FragmentManager.java:3706)
android.support.v4.app.FragmentController.onCreateView (FragmentController.java:111)
android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView (FragmentActivity.java:338)
android.support.v4.app.BaseFragmentActivityApi14.onCreateView (BaseFragmentActivityApi14.java:39)
android.support.v4.app.FragmentActivity.onCreateView (FragmentActivity.java:67)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:754)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704)
android.view.LayoutInflater.rInflate (LayoutInflater.java:835)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
android.view.LayoutInflater.inflate (LayoutInflater.java:515)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
android.view.LayoutInflater.inflate (LayoutInflater.java:374)
com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:393)
android.app.Activity.setContentView (Activity.java:2215)
com.app.Activities.Activities.PrincipalActivity.onCreate (PrincipalActivity.java:60)
android.app.Activity.performCreate (Activity.java:6323)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1108)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2387)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2494)
android.app.ActivityThread.access$900 (ActivityThread.java:153)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1347)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5451)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

Activity:

public class PrincipalActivity extends FragmentActivity {

    private FragmentManager fragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_principal);

             mFragmentManager = getSupportFragmentManager();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_place, anotherFragment).commit();

Activity XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:design="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_principal2"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.app.Activities.Activities.PrincipalActivity">

    <fragment
        android:id="@+id/fragment_place"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/divider"
        class = "com.app.Activities.Activities.EmptyFragment"
        />

Fragment XML:

<RelativeLayout 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.app.Activities.Activities.EmptyFragment">


</RelativeLayout>

Fragment class:

public class EmptyFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_empty, container, false);



        return v;
    }


}

1 Answers1

0

try to change your fragment.

from:

<fragment
        android:id="@+id/fragment_place"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/divider"
        class = "com.app.Activities.Activities.EmptyFragment"
        />

to:

<fragment
        android:name="com.app.Activities.Activities.EmptyFragment"
        android:id="@+id/fragment_place"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/divider"
        />

and remove this line of code to yourPrincipalActivity.

mFragmentManager = getSupportFragmentManager();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_place, anotherFragment).commit();

Hope this help!

dotGitignore
  • 1,597
  • 2
  • 15
  • 34
  • It was my first code. I changed because was happening the same problem and in other questions was saying to do it. – Rodrigo Taborda Oct 19 '17 at 01:35
  • @RodrigoTaborda I tried this with your code, but mine is working. can you show us where the `EmptyFragment` located? – dotGitignore Oct 19 '17 at 01:48
  • @RodrigoTaborda I think you need to double check your `EmptyFragment` so you can modify the value of `android:name` of your `fragment` – dotGitignore Oct 19 '17 at 01:49
  • Those are the same behavior. https://stackoverflow.com/questions/10162983/activity-layout-fragment-class-vs-androidname-attributes – OneCricketeer Oct 19 '17 at 16:19
  • @Jerrol. Mine is working fine too. I'm getting this error via Firebase. There are many instances, but I cannot fix. I already tried "name" and "class", but as cricket_007 said, they have the same behavior. – Rodrigo Taborda Oct 22 '17 at 23:42
  • @RodrigoTaborda, Ohh, I think you need to provide more or update your codes in question more specifically. because the code shown is working fine (like what I did I copied your code and it's working). – dotGitignore Oct 23 '17 at 00:20
  • **It just happen in some devices (sometimes) and I'm not able to solve it.** as your statement. did you try to change your `FragmentActivity` to `AppCompatActivity`? – dotGitignore Oct 23 '17 at 00:22