Error: android.view.InflateException: Binary XML file line # 0: Error inflating class unknown

1

Whenever I run my app on some devices (In those I got this error, API was 21. In others with higher API it works without errors), this error message appears that I can not decipher. It happens for all Fragments in the same way, but the app closes soon.

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: edurbrito.SuperLigaUsers, PID: 2738
              android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
                  at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                  at edurbrito.SuperLigaUsers.Fragments.Main_Activity_Fragments.ThreeFragment.onCreateView(ThreeFragment.java:71)
                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                  at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                  at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                  at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                  at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                  at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2209)
                  at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649)
                  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
                  at android.support.v4.view.ViewPager.populate(ViewPager.java:1238)
                  at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
                  at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1616)
                  at android.view.View.measure(View.java:17430)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
                  at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
                  at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
                  at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
                  at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
                  at android.view.View.measure(View.java:17430)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
                  at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                  at android.view.View.measure(View.java:17430)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
                  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                  at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                  at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                  at android.view.View.measure(View.java:17430)
                  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
                  at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
                  at android.view.View.measure(View.java:17430)
                  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
                  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)
                  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
                  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
                  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:580)
                  at android.view.Choreographer.doFrame(Choreographer.java:550)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
                at andro ...(O erro acaba assim sem mais explicação ou causa)

This is the layout:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    android:id="@+id/linearLayout3"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="5"
    app:layout_constraintBottom_toTopOf="@+id/sticky_switch"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:id="@+id/ColunaClassificacao"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/layout_bg_without_margin"
        android:elevation="5dp"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="125dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:orientation="horizontal"
            android:paddingStart="7.5dp"
            tools:ignore="RtlSymmetry">

            <TextView
                android:id="@+id/LugarCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:gravity="center"
                android:text="# - "
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/NomeEquipaCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Equipa"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:weightSum="5">

            <TextView
                android:id="@+id/JogosCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="JJ"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/PontosCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Pts"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/GolosMarcadosCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="GM"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/GolosSofridosCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="GS"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/DiferençaGolosCC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="DG"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold" />

        </LinearLayout>
    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_three"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/layout_bg2"
        android:elevation="5dp"
        android:padding="5dp"
        app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ColunaClassificacao">

    </android.support.v7.widget.RecyclerView>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@+id/switchCampeonato1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/layout_bg_without_margin"
            android:padding="5dp"
            android:text="Campeonato"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/switchball3"
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:src = "@drawable/soccer_ball"/>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

And this is the class:

    import android.Manifest;
    import android.content.pm.PackageManager;
    import android.os.Bundle;
    import android.os.Environment;
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.app.Fragment;
    import android.support.v4.content.ContextCompat;
    import android.support.v7.widget.LinearLayoutManager;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.ImageView;
    import android.widget.TextView;

    import com.google.gson.Gson;
    import com.google.gson.reflect.TypeToken;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.lang.reflect.Type;
    import java.nio.charset.Charset;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeMap;

 import edurbrito.SuperLigaUsers.Adapters.RVAdapterClassificacao;
 import edurbrito.SuperLigaUsers.Colunas.ClassificacaoTabela;
 import edurbrito.SuperLigaUsers.Objetos.Campeonato1;
 import edurbrito.SuperLigaUsers.Objetos.Campeonato2;
 import edurbrito.SuperLigaUsers.Objetos.Objeto_Equipa;
 import edurbrito.SuperLigaUsers.R;


public class ThreeFragment extends Fragment {
private final int MY_PERMISSIONS_REQUEST = 11;
protected RecyclerView rv;
protected RecyclerView.LayoutManager mLayoutManager;
Runnable runnable = null;
private List<ClassificacaoTabela> Classificacao;

public ThreeFragment() {
    // Required empty public constructor
}

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

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View rootView;
    rootView = inflater.inflate(R.layout.fragment_three, container, false);

   final TextView switchCampeonato = rootView.findViewById(R.id.switchCampeonato1);
   final ImageView switchball = rootView.findViewById(R.id.switchball3);

    final Campeonato1 campeonato1 = new Campeonato1();
    final Campeonato2 campeonato2 = new Campeonato2();
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(getActivity(),
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                MY_PERMISSIONS_REQUEST);

    } else {

       switchCampeonato.setText(campeonato1.getNome());
        switchball.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (switchCampeonato.getText().toString().equals(campeonato1.getNome())) {

                    Animation animation;
                    animation = AnimationUtils.loadAnimation(getActivity(),
                            R.anim.rotate);

                    switchball.startAnimation(animation);
                    switchCampeonato.setText(campeonato2.getNome());
                    runnable.run();
                } else {

                    Animation animation;
                    animation = AnimationUtils.loadAnimation(getActivity(),
                            R.anim.rotate);

                    switchball.startAnimation(animation);
                    switchCampeonato.setText(campeonato1.getNome());
                    runnable.run();
                }
            }
        });


        Type MapaTipoEquipas = new TypeToken<Map<String, Objeto_Equipa>>() {
        }.getType();
        String mapaDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/SuperLiga";
        File MapaFile = new File(mapaDirectory, "MapaEquipas1.txt");


        Gson gson = new Gson();


        String string = "";


        try {
            BufferedReader fis2 = new BufferedReader(
                    new InputStreamReader(
                            new FileInputStream(MapaFile),
                            Charset.forName("UTF-8")));
            int content;
            while ((content = fis2.read()) != -1) {
                // convert to char and display it
                string += (char) content;
            }


        } catch (IOException e) {
            e.printStackTrace();
        }

        Map<String, Objeto_Equipa> mapaEquipas;
        mapaEquipas = gson.fromJson(string, MapaTipoEquipas);

        Set<String> keys = mapaEquipas.keySet();
        String[] listaNomesEqs = keys.toArray(new String[keys.size()]);
        TreeMap<String, Objeto_Equipa> treeMap = new TreeMap<>(Collections.reverseOrder());
        for (int i = 0; i < listaNomesEqs.length; i++) {
            treeMap.put(mapaEquipas.get(listaNomesEqs[i]).getFinalString(), mapaEquipas.get(listaNomesEqs[i]));
        }


        List<Objeto_Equipa> targetList = new ArrayList<>(treeMap.values());
        Classificacao = new ArrayList<>();
        for (int i = 0; i < targetList.size(); i++) {
            Objeto_Equipa equipa = targetList.get(i);
            Classificacao.add(i, new ClassificacaoTabela("" + (i + 1), equipa.getNome(), equipa.getJogos(), equipa.getPontos(), equipa.getGolosM(), equipa.getGolosS(), equipa.getGolosM() - equipa.getGolosS()));
        }
        rv = (RecyclerView) rootView.findViewById(R.id.rv_three);
        mLayoutManager = new LinearLayoutManager(getActivity());
        rv.setLayoutManager(mLayoutManager);


        RVAdapterClassificacao adapter = new RVAdapterClassificacao(Classificacao, getActivity());

        rv.setAdapter(adapter);

    }

    runnable = new Runnable() {
        @Override
        public void run() {

            Type MapaTipoEquipas = new TypeToken<Map<String, Objeto_Equipa>>() {
            }.getType();
            String mapaDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/SuperLiga";
            File MapaFile;


           if (switchCampeonato.getText().toString().equals(campeonato1.getNome())) {
               MapaFile = new File(mapaDirectory, "MapaEquipas1.txt");

            } else {
                MapaFile = new File(mapaDirectory, "MapaEquipas2.txt");
            }


            Gson gson = new Gson();


            String string = "";


            try {
                BufferedReader fis2 = new BufferedReader(
                        new InputStreamReader(
                                new FileInputStream(MapaFile),
                                Charset.forName("UTF-8")));
                int content;
                while ((content = fis2.read()) != -1) {
                    // convert to char and display it
                    string += (char) content;
                }


            } catch (IOException e) {
                e.printStackTrace();
            }

            Map<String, Objeto_Equipa> mapaEquipas;
            mapaEquipas = gson.fromJson(string, MapaTipoEquipas);

            Set<String> keys = mapaEquipas.keySet();
            String[] listaNomesEqs = keys.toArray(new String[keys.size()]);
            TreeMap<String, Objeto_Equipa> treeMap = new TreeMap<>(Collections.reverseOrder());
            for (int i = 0; i < listaNomesEqs.length; i++) {
                treeMap.put(mapaEquipas.get(listaNomesEqs[i]).getFinalString(), mapaEquipas.get(listaNomesEqs[i]));
            }


            List<Objeto_Equipa> targetList = new ArrayList<>(treeMap.values());
            Classificacao = new ArrayList<>();
            for (int i = 0; i < targetList.size(); i++) {
                Objeto_Equipa equipa = targetList.get(i);
                Classificacao.add(i, new ClassificacaoTabela("" + (i + 1), equipa.getNome(), equipa.getJogos(), equipa.getPontos(), equipa.getGolosM(), equipa.getGolosS(), equipa.getGolosM() - equipa.getGolosS()));
            }
            rv = (RecyclerView) rootView.findViewById(R.id.rv_three);
            mLayoutManager = new LinearLayoutManager(getActivity());
            rv.setLayoutManager(mLayoutManager);


            RVAdapterClassificacao adapter = new RVAdapterClassificacao(Classificacao, getActivity());

            rv.setAdapter(adapter);
        }
    };


    // Inflate the layout for this fragment
    return null;
}

}

And this is the activity xml

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="@dimen/custom_tab_layout_height"
        app:tabMode="fixed"
        app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"  />

    
asked by anonymous 25.07.2018 / 14:46

0 answers