二进制 XML 文件第 17 行:UnsupportedOperationException 导致的类 <unknown> 膨胀错误:无法转换为维度:type=0x2
Posted
技术标签:
【中文标题】二进制 XML 文件第 17 行:UnsupportedOperationException 导致的类 <unknown> 膨胀错误:无法转换为维度:type=0x2【英文标题】:Binary XML file line #17: Error inflating class <unknown> caused by UnsupportedOperationException: Can't convert to dimension: type=0x2 【发布时间】:2014-01-28 01:22:36 【问题描述】:我一直在尝试运行我的应用程序 (android),但是当出现以下异常时它会崩溃
[LogCat]
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at emy.dt4it.healthytips.NavDrawerListAdapter.getView(NavDrawerListAdapter.java:46)
at android.widget.AbsListView.obtainView(AbsListView.java:1315)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
at android.widget.ListView.onMeasure(ListView.java:1109)
at android.view.View.measure(View.java:8171)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
at com.slidinglayer.SlidingLayer.onMeasure(SlidingLayer.java:1077)
at android.view.View.measure(View.java:8171)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
at android.view.View.measure(View.java:8171)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
at android.view.View.measure(View.java:8171)
at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.TextView.<init>(TextView.java:321)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 37 more
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
at android.view.View.<init>(View.java:2036)
at android.widget.TextView.<init>(TextView.java:327)
... 41 more
01-09 11:38:22.923: I/Process(15758): Sending signal. PID: 15758 SIG: 9
以及该行中的异常
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
在那个类中:[NavDrawerListAdapter.java]
package emy.dt4it.healthytips;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class NavDrawerListAdapter extends BaseAdapter
private Context context;
private ArrayList<NavDrawerItem> navDrawerItems;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerItem> navDrawerItems)
this.context = context;
this.navDrawerItems = navDrawerItems;
@Override
public int getCount()
return navDrawerItems.size();
@Override
public Object getItem(int position)
return navDrawerItems.get(position);
@Override
public long getItemId(int position)
return position;
@Override
public View getView(int position, View convertView, ViewGroup parent)
if (convertView == null)
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
TextView txtCount = (TextView) convertView.findViewById(R.id.counter);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/bauhausm_0.ttf");
txtTitle.setTypeface(tf);
txtCount.setTypeface(tf);
imgIcon.setImageResource(navDrawerItems.get(position).getIcon());
txtTitle.setText(navDrawerItems.get(position).getTitle());
// displaying count
// check whether it set visible or not
if(navDrawerItems.get(position).getCounterVisibility())
txtCount.setText(navDrawerItems.get(position).getCount());
else
// hide the counter view
txtCount.setVisibility(View.GONE);
return convertView;
和布局 [drawer_list_item]
<RelativeLayout android:layout_
android:layout_
android:background="@drawable/list_selector">
<ImageView android:id="@+id/icon"
android:layout_
android:layout_
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:src="@drawable/menu_tip"
android:layout_centerVertical="true"/>
<TextView android:id="@+id/title"
android:layout_
android:layout_
android:layout_toRightOf="@id/icon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#4f4f4f"
android:textSize="18sp"
android:text="try"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="@+id/counter"
android:layout_
android:layout_
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="2"
android:layout_marginRight="8dp"
android:textColor="#959595"/>
</RelativeLayout>
希望有人能帮助我。提前致谢。
【问题讨论】:
使用的是什么 SDK 版本? android:attr/listPreferredItemHeightSmall 和 android:attr/textAppearanceListItemSmall 在 API 级别 14 及更高级别可用(请参阅developer.android.com/reference/android/R.attr.html)。 请显示您的来源(在本网站上,而不是通过链接)。 @MártonMolnár 你是对的,谢谢它现在工作。我正在使用 api 8 【参考方案1】:xml 中的错误 检查您是否在提交的第 17 行。
android:attr/textAppearanceListItemSmall
如果这里的错误是清单中的 api 级别更改
【讨论】:
【参考方案2】:最里面的异常意味着您的其中一个文本视图声明了无效的尺寸。检查您正在使用的 SDK 级别,因为 android:attr/listPreferredItemHeightSmall
和 android:attr/textAppearanceListItemSmall
可用于 API 级别 14 及更高级别。
(从解决问题的我的评论中添加)
【讨论】:
【参考方案3】:我在同一行发现了同样的错误,花了两天时间才确定错误是什么。
错误只是因为我试图使用一个:android:background
而不是:app:srcCompat
在 SVG 文件中。
在你的情况下,
<ImageView android:id="@+id/icon"
android:layout_
android:layout_
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:src="@drawable/menu_tip" <-- the error is here
android:layout_centerVertical="true"/>
如果您正在使用,也会出现错误:android:src=" "
我希望这会有所帮助。
【讨论】:
以上是关于二进制 XML 文件第 17 行:UnsupportedOperationException 导致的类 <unknown> 膨胀错误:无法转换为维度:type=0x2的主要内容,如果未能解决你的问题,请参考以下文章
android.view.InflateException:二进制 XML 文件第 15 行:二进制 XML 文件第 19 行:膨胀类片段时出错
Google Map API 问题:android.view.InflateException:二进制 XML 文件第 2 行:二进制 XML 文件第 2 行:膨胀类片段时出错
当我切换到包含片段的活动时应用程序崩溃(二进制 XML 文件第 10 行:二进制 XML 文件第 10 行:膨胀类片段时出错)
如何摆脱问题'二进制XML文件第8行:二进制XML文件第8行:使用XYPlot时会膨胀类com.androidplot.xy.XYPlot类]