Error android.view.Inflateexception: Binary XML file line

Asked

Viewed 1,040 times

0

note the error message!

2020-01-03 16:37:48.091 27513-27513/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.resource.listfragment, PID: 27513
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.resource.listfragment/com.resource.listfragment.MainActivity}: android.view.InflateException: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: android.view.InflateException: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Error inflating class fragment
     Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.resource.listfragment.ListProdutosFragments that is not a Fragment
        at android.app.Fragment.instantiate(Fragment.java:538)
        at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
        at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3553)
        at android.app.FragmentController.onCreateView(FragmentController.java:104)
        at android.app.Activity.onCreateView(Activity.java:6948)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:438)
        at android.app.Activity.setContentView(Activity.java:3324)
        at com.resource.listfragment.MainActivity.onCreate(MainActivity.java:19)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-01-03 16:37:48.091 27513-27513/? E/AndroidRuntime: Caused by: java.lang.ClassCastException
        ... 31 more
2020-01-03 16:37:48.110 27513-27513/? I/Process: Sending signal. PID: 27513 SIG: 9

Informs that the error is in this class.

package com.resource.listfragment;

import android.app.Activity;
import android.os.Bundle;

import java.text.NumberFormat;
import java.util.Locale;

public class MainActivity extends Activity implements ListProdutosFragments.OnItemClick {

    private static final NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));

    private DescProdutosFragments textFrag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        textFrag = (DescProdutosFragments) getFragmentManager().findFragmentById(R.id.frag_text);
    }

    @Override
    public void onClick(Alimento alimento) {
        textFrag.setText(String.format("O preço do %s é %s", alimento.getNome(), nf.format(alimento.getPreco())));
    }
}

More precisely on that line.

setContentView(R.layout.activity_main);

This is my XML file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:padding="16dp" >

    <fragment
        android:id="@+id/frag_list"
        android:name="com.resource.listfragment.ListProdutosFragments"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        tools:layout="@android:layout/simple_list_item_1" />

    <fragment
        android:id="@+id/frag_text"
        android:name="com.resource.listfragment.DescProdutosFragments"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        tools:layout="@layout/fragment_test" />


</LinearLayout>

What would be the suggestion to correct the problem?

  • Activity xml is poorly formed.

  • I just posted my xml @Daviaragao could take a look at?

  • 2

    Trying to instantiate a class com.resource.listfragment.ListProdutosFragments that is not a Fragment -- The error is stating that the class ListProdutosFragments is not a Fragment

  • Our guy, you managed to help me, thank you very much, I put the wrong import. thanks even @Andréribeiro

  • i had put this androidx.fragment.app.Listfragment import and it was actually supposed to be this android.app.Listfragment import;

  • Don’t forget to add an answer explaining what the problem was and how you solved it. That way whoever falls here with the same mistake will know what it is and how to solve (it is clearer than leaving in the comments).

Show 1 more comment

1 answer

1


The problem was in the act of importing the correct package, I had imported that package.

inserir a descrição da imagem aqui

and stayed like this!

inserir a descrição da imagem aqui

But the right package is this!

inserir a descrição da imagem aqui

After I put the right package worked perfectly.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.