web-dev-qa-db-ja.com

クラスImageViewの膨張エラー-Android.view.InflateException:Binary XML file line#10:Error inflatating class ImageView

リストアイテム用のxmlファイル(list_item.xml)と、リストビュー用のアダプター(NewsAdapter.Java)を備えたアプリを設計しています。

私のアプリは実行中にこのエラーが発生します:

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

私のlist_itemファイルにはImageViewがあります:

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

List_item.xmlからImageViewを削除すると、アプリは正常に実行されます。

私は何をすべきか?!

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

エラーの最後の行にあるように:

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

あなたがしなければならない次元ではない何かを入力したようです。そして属性のドキュメントとしてAndroid:baseline

このビュー内のベースラインのオフセット。 「14.5sp」などの単位が追加された浮動小数点数であるディメンション値の場合があります。使用可能な単位は、px(ピクセル)、dp(密度非依存ピクセル)、sp(推奨フォントサイズに基づいてスケーリングされたピクセル)、in(インチ)、mm(ミリメートル)です。

しかし、ベースラインの値に文字列を使用しました。

6
David

ドローアブルで画像ファイルをコピーしている間、ドローアブルとドローアブル-24の両方でコピーするオプションが表示されます。両方をコピーしてから実行してみてください。

9
Ragas

アプリケーションにも同じ問題がありましたが、ようやく解決しました。画像ファイルをic_launcher_foreground.xmlファイルではなくic_launcher_background.xmlファイルに配置するだけです。

1
Swaruuu