web-dev-qa-db-fra.com

Erreur de gonflage de la classe ImageView - Android.view.InflateException: ligne de fichier XML binaire n ° 10: erreur de gonflage de la classe ImageView

Je conçois une application comportant un fichier XML pour les éléments de la liste (list_item.xml), Et un adaptateur pour le listView (NewsAdapter.Java).

Mon application rencontre cette erreur lors de l'exécution:

09-22 20:26:29.595 10387-10387/com.example.rh.newsapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.example.rh.newsapp, PID: 10387
                                                                    Android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class ImageView
                                                                        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:539)
                                                                        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:423)
                                                                        at com.example.rh.newsapp.NewsAdapter.getView(NewsAdapter.Java:38)
                                                                        at Android.widget.AbsListView.obtainView(AbsListView.Java:2346)
                                                                        at Android.widget.ListView.measureHeightOfChildren(ListView.Java:1280)
                                                                        at Android.widget.ListView.onMeasure(ListView.Java:1188)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951)
                                                                        at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1465)
                                                                        at Android.widget.LinearLayout.measureHorizontal(LinearLayout.Java:1112)
                                                                        at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:632)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951)
                                                                        at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:194)
                                                                        at Android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.Java:139)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951)
                                                                        at Android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.Java:391)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951)
                                                                        at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:194)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951)
                                                                        at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1465)
                                                                        at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:748)
                                                                        at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:630)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951)
                                                                        at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:194)
                                                                        at com.Android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.Java:2643)
                                                                        at Android.view.View.measure(View.Java:18788)
                                                                        at Android.view.ViewRootImpl.performMeasure(ViewRootImpl.Java:2100)
                                                                        at Android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.Java:1216)
                                                                        at Android.view.ViewRootImpl.performTraversals(ViewRootImpl.Java:1452)
                                                                        at Android.view.ViewRootImpl.doTraversal(ViewRootImpl.Java:1107)
                                                                        at Android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.Java:6013)
                                                                        at Android.view.Choreographer$CallbackRecord.run(Choreographer.Java:858)
                                                                        at Android.view.Choreographer.doCallbacks(Choreographer.Java:670)
                                                                        at Android.view.Choreographer.doFrame(Choreographer.Java:606)
                                                                        at Android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.Java:844)
                                                                        at Android.os.Handler.handleCallback(Handler.Java:739)
                                                                        at Android.os.Handler.dispatchMessage(Handler.Java:95)
                                                                        at Android.os.Looper.loop(Looper.Java:148)
                                                                        at Android.app.ActivityThread.main(ActivityThread.Java:5417)
                                                                        at Java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:726)
                                                                        at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:616)
                                                                     Caused by: Android.view.InflateException: Binary XML file line #10: Error inflating class ImageView
                                                                        at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:782)
                                                                        at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:704)
                                                                        at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:835)
                                                                        at Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:798)
                                                                        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:515)
                                                                        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:423) 
                                                                        at com.example.rh.newsapp.NewsAdapter.getView(NewsAdapter.Java:38) 
                                                                        at Android.widget.AbsListView.obtainView(AbsListView.Java:2346) 
                                                                        at Android.widget.ListView.measureHeightOfChildren(ListView.Java:1280) 
                                                                        at Android.widget.ListView.onMeasure(ListView.Java:1188) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951) 
                                                                        at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1465) 
                                                                        at Android.widget.LinearLayout.measureHorizontal(LinearLayout.Java:1112) 
                                                                        at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:632) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951) 
                                                                        at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:194) 
                                                                        at Android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.Java:139) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951) 
                                                                        at Android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.Java:391) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951) 
                                                                        at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:194) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951) 
                                                                        at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1465) 
                                                                        at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:748) 
                                                                        at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:630) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5951) 
                                                                        at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:194) 
                                                                        at com.Android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.Java:2643) 
                                                                        at Android.view.View.measure(View.Java:18788) 
                                                                        at Android.view.ViewRootImpl.performMeasure(ViewRootImpl.Java:2100) 
                                                                        at Android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.Java:1216) 
                                                                        at Android.view.ViewRootImpl.performTraversals(ViewRootImpl.Java:1452) 
                                                                        at Android.view.ViewRootImpl.doTraversal(ViewRootImpl.Java:1107) 
                                                                        at Android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.Java:6013) 
                                                                        at Android.view.Choreographer$CallbackRecord.run(Choreographer.Java:858) 
                                                                        at Android.view.Choreographer.doCallbacks(Choreographer.Java:670) 
                                                                        at Android.view.Choreographer.doFrame(Choreographer.Java:606) 
                                                                        at Android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.Java:844) 
                                                                        at Android.os.Handler.handleCallback(Handler.Java:739) 
                                                                        at Android.os.Handler.dispatchMessage(Handler.Java:95) 
                                                                        at Android.os.Looper.loop(Looper.Java:148) 
                                                                        at Android.app.ActivityThread.main(ActivityThread.Java:5417) 
                                                                        at Java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:726) 
                                                                        at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:616) 
                                                                     Caused by: Java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
                                                                        at Android.content.res.TypedArray.getDimensionPixelSize(TypedArray.Java:666)
                                                                        at Android.widget.ImageView.<init>(ImageView.Java:160)
                                                                        at Android.widget.ImageView.<init>(ImageView.Java:140)
                                                                        at Android.suppor

Mon fichier list_item a unImageView:

<ImageView
    Android:id="@+id/thumbnail"
    Android:layout_width="40dp"
    Android:layout_height="wrap_content"
    Android:baseline="@id/title"
    app:srcCompat="@Android:drawable/ic_lock_lock"
    tools:ignore="NotSibling" />

Lorsque je supprime ImageView du fichier list_item.xml, l'application fonctionne bien!

Que devrais-je faire?!

NewsAdapter.Java:

public class NewsAdapter extends ArrayAdapter {
Context context;
List<News> newsList;

public NewsAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List objects) {
    super(context, resource, objects);
    this.context = context;
    this.newsList = objects;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    News current_news = (News) getItem(position);
    View list_view = convertView;
    if(list_view == null) {
        list_view = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
    }

    TextView title = list_view.findViewById(R.id.title);
    TextView publicationDate = list_view.findViewById(R.id.publicationDate);
    TextView publication = list_view.findViewById(R.id.publication);

    title.setText(current_news.getTitle());
    publicationDate.setText(current_news.getPublication_date());
    publication.setText(current_news.getPublication());

    return list_view;
}

}

list_item.xml:

<ImageView
    Android:id="@+id/thumbnail"
    Android:layout_width="40dp"
    Android:layout_height="wrap_content"
    Android:baseline="@id/title"
    app:srcCompat="@Android:drawable/ic_lock_lock"
    tools:ignore="NotSibling" />

<RelativeLayout
    Android:layout_width="match_parent"
    Android:layout_height="wrap_content"
    Android:layout_marginLeft="16dp">

    <TextView
        Android:id="@+id/title"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignParentLeft="true"
        Android:layout_alignParentTop="true"
        Android:ellipsize="end"
        Android:maxLines="3"
        tools:text="Is technology delivering in schools? Our panel debates" />

    <LinearLayout
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_below="@+id/title"
        Android:layout_alignParentLeft="true"
        Android:orientation="horizontal">

        <TextView
            Android:id="@+id/publicationDate"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            tools:text="27 Nov, 2016" />

        <TextView
            Android:id="@+id/pipe_icon"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:text="@string/separator_icon" />

        <TextView
            Android:id="@+id/publication"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:ellipsize="end"
            Android:maxLines="1"
            tools:text="The Guardian" />
    </LinearLayout>

</RelativeLayout>

4
roghayeh hosseini

Comme vous le voyez dans les dernières lignes d'erreur:

Caused by: Java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12

il semble que vous ayez entré quelque chose qui ne soit pas une dimension où vous devez . Et comme documentation de l'attribut Android:baseline:

Le décalage de la ligne de base dans cette vue. Peut-être une valeur de dimension, qui est un nombre à virgule flottante ajouté à une unité telle que "14.5sp". Les unités disponibles sont les suivantes: px (pixels), dp (pixels indépendants de la densité), sp (pixels redimensionnés en fonction de la taille de police préférée), en pouces, et mm (millimètres).

Mais vous avez utilisé une chaîne pour la valeur de référence.

6
David

lors de la copie des fichiers image dans Drawable, vous aurez la possibilité de copier en Drawable et Drawable-24 Assurez-vous de copier dans les deux et essayez ensuite de courir.

6
Ragas

J'ai eu le même problème avec mon application mais finalement je l'ai résolu .. .. Il suffit de mettre votre fichier image dans le fichier ic_launcher_background.xml au lieu du fichier ic_launcher_foreground.xml.Espoir que cela aide.

1
Swaruuu