web-dev-qa-db-fra.com

InflateException: ligne de fichier XML binaire n ° 8: erreur lors du gonflage de la classe ImageView

Je sais qu'il y a d'autres questions sur SO qui demandent la même chose. J'ai déjà regardé la plupart d'entre eux. 

La plupart des réponses appellent des erreurs de mémoire. Je ne vois pas comment une ImageView qui ne charge qu'une petite icône (24x24 pixels) peut créer quelque chose comme ceci.

Mais je voudrais poster le stacktrace ici peut-être que quelqu'un d'autre peut identifier quelque chose que je ne peux pas et m'aider.

06-03 22:14:17.367 28590-28590/css.mvp.example.debug W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41e4ad40)
06-03 22:14:17.409 28590-28590/css.mvp.example.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: css.mvp.example.debug, PID: 28590  Android.view.InflateException: Binary XML file line #8: Error inflating class ImageView
    at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:713)
    at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:755)
    at Android.view.LayoutInflater.inflate(LayoutInflater.Java:492)
    at Android.view.LayoutInflater.inflate(LayoutInflater.Java:397)
    at css.mvp.example.main.projects.fragments.adapters.PollAnswersAdapter.getView(PollAnswersAdapter.Java:38)
    at Android.widget.AbsListView.obtainView(AbsListView.Java:2255)
    at Android.widget.ListView.measureHeightOfChildren(ListView.Java:1263)
    at Android.widget.ListView.onMeasure(ListView.Java:1175)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1404)
    at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:695)
    at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:588)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.Java:668)
    at Android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.Java:735)
    at Android.view.View.measure(View.Java:16540)
    at Android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.Java:1075)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
    at Android.view.View.measure(View.Java:16540)
    at Android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.Java:719)
    at Android.widget.RelativeLayout.onMeasure(RelativeLayout.Java:455)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
    at Android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.Java:135)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1404)
    at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:695)
    at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:588)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1404)
    at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:695)
    at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:588)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5137)
    at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
    at com.Android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.Java:2291)
    at Android.view.View.measure(View.Java:16540)
    at Android.view.ViewRootImpl.performMeasure(ViewRootImpl.Java:1942)
    at Android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.Java:1132)
    at Android.view.ViewRootImpl.performTraversals(ViewRootImpl.Java:1321)
    at Android.view.ViewRootImpl.doTraversal(ViewRootImpl.Java:1019)
    at Android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.Java:5725)

Fichier de mise en page 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout   xmlns:Android="http://schemas.Android.com/apk/res/Android" Android:orientation="horizontal"
Android:weightSum="11"
Android:paddingTop="16dp" Android:paddingBottom="16dp"
Android:gravity="center_horizontal"
Android:layout_width="match_parent" Android:layout_height="wrap_content">

<ImageView
    Android:id="@+id/iv_answer_circle"
    Android:src="@drawable/ic_dot"
    Android:layout_gravity="center" Android:layout_weight="2"
    Android:layout_marginLeft="16dp" Android:layout_marginRight="16dp"
    Android:layout_width="0dp" Android:layout_height="wrap_content" />

<TextView Android:id="@+id/tv_poll_answer"
    Android:layout_weight="6"
    Android:layout_width="0dp" Android:layout_height="wrap_content" />

<TextView Android:id="@+id/tv_poll_answer_num"
    Android:layout_weight="1"
    Android:layout_marginLeft="16dp" Android:layout_marginRight="8dp"
    Android:layout_width="0dp" Android:layout_height="wrap_content" />

<TextView Android:id="@+id/tv_poll_answer_percent"
    Android:layout_weight="2"
    Android:layout_marginRight="16dp"
    Android:layout_width="0dp" Android:layout_height="wrap_content" />

</LinearLayout>

EDIT 2: le code de ma classe d'adaptateur.

public class PollAnswersAdapter extends ArrayAdapter<PollAnswerItem> {

    private Context context;
    private ArrayList<PollAnswerItem> data;


    public PollAnswersAdapter(Context context, ArrayList<PollAnswerItem> data) {
        super(context, -1, data);
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.row_answer, parent, false);

        ImageView ivCircle = (ImageView) rowView.findViewById(R.id.iv_answer_circle);
        TextView tvAnswer = (TextView) rowView.findViewById(R.id.tv_poll_answer);
        TextView tvNums = (TextView) rowView.findViewById(R.id.tv_poll_answer_num);
        TextView tvPercent = (TextView) rowView.findViewById(R.id.tv_poll_answer_percent);

        tvAnswer.setText(data.get(position).getAnswer());
        tvNums.setText(data.get(position).getNum());
        tvPercent.setText(data.get(position).getPercent() + "%");
        tvPercent.setTextColor(ColorTemplate.PREDEFINED_COLORS[position]);

        return rowView;
    }

}
9
Mes

La trace de la pile ne le montre pas, mais l'erreur lors de l'inflation peut provenir de drawable utilisé dans ImageView, dans ce cas:

Android:src="@drawable/ic_dot"

OP a testé cette intuition en essayant un dessin différent qui " semble bien pour le moment ... ".

17
Marcin Koziński

ligne de fichier xml binaire n ° 0: erreur lors de l'inflatable de la classe imageview

vous devez voir si votre image est devenue drawable-v23 ou v24, ce qui pourrait être supérieur au niveau de votre OS mobile

exemple Dans le dossier pouvant être dessiné ~> "ic_contact (v24)" 

23
Aashay karekar

Si vous utilisez des objets vectoriels, utilisez

app:srcCompat="@drawable/ic_dot"

au lieu de 

Android:src="@drawable/ic_dot"
11
pedroca

utilisation 

app:srcCompat="@drawable/ic_dot" 

ne pas

Android:src="@drawable/ic_dot" 
2
felhi

Le code suivant pourrait être ajouté dans Android Manifests-Activity

<activity
Android:name=""
--------------
Android:theme="@Android:style/Theme.Black.NoTitleBar">
</activity>

veuillez supprimer ce thème si vous avez ajouté.

Mon problème a été résolu après la suppression de ce thème. J'ai eu cette solution après longtemps.

0
Nitin Karale