gpt4 book ai didi

android - 膨胀异常 : Binary XML file line #8: Error inflating class ImageView

转载 作者:IT老高 更新时间:2023-10-28 23:16:37 24 4
gpt4 key购买 nike

我知道在 SO 上还有其他问题问同样的问题。我已经看过其中的大部分。

大多数答案都与内存错误有关。我看不出只加载一个小图标(24x24 像素)的 ImageView 是如何做出这样的事情的。

但我想在这里发布堆栈跟踪,也许其他人可以识别我无法识别的东西并帮助我。

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)

布局文件

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

编辑 2:我的适配器类的代码。

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

}

最佳答案

二进制 xml 文件第 0 行:膨胀类 imageview 时出错

你必须看看你的图片是否变成了drawable-v23或v24,这可能高于你的移动操作系统级别,确保避免在项目中创建可绘制版本的图片

示例在drawable文件夹中~> "ic_contact(v24)"

关于android - 膨胀异常 : Binary XML file line #8: Error inflating class ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37621934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com