wake-up-neo.com

Fehler beim Aufblasen der Klasse ImageView - Android.view.InflateException: Binäre XML-Dateizeile # 10: Fehler beim Aufblasen der Klasse ImageView

Ich entwerfe eine App, die eine XML-Datei für die Listenelemente (list_item.xml), Und einen Adapter für die Listenansicht (NewsAdapter.Java) enthält.

Meine App stößt bei der Ausführung auf diesen Fehler:

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

Meine list_item-Datei hat eineImageView:

<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" />

Wenn ich ImageView aus der list_item.xml lösche, läuft die App gut!

Was soll ich machen?!

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

Wie Sie in den letzten Fehlerzeilen sehen:

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

anscheinend haben Sie etwas eingegeben, bei dem es sich nicht um eine Dimension handelt, in der Sie ... und als Dokumentation des Attributs Android:baseline:

Der Versatz der Grundlinie innerhalb dieser Ansicht. Kann ein Dimensionswert sein Hierbei handelt es sich um eine Fließkommazahl, an die eine Einheit angehängt wird, z. "14.5sp". Verfügbare Einheiten sind: px (Pixel), dp (dichteunabhängige Pixel), sp (skalierte Pixel basierend auf der bevorzugten Schriftgröße), in (Zoll), und mm (Millimeter).

Sie haben jedoch eine Zeichenfolge als Basiswert verwendet.

6
David

beim Kopieren der Bilddateien in drawable können Sie sowohl in drawable als auch drawable-24 kopieren. Stellen Sie sicher, dass Sie in beide kopieren und dann versuchen, sie auszuführen.

6
Ragas

Ich hatte das gleiche Problem mit meiner Anwendung, aber schließlich habe ich es gelöst .. __ Legen Sie einfach Ihre Bilddatei in die Datei ic_launcher_background.xml anstelle der Datei ic_launcher_foreground.xml.

1
Swaruuu