android – 二进制XML文件行#17:由UnsupportedOperationException引起的冒充类错误:无法转换为维:type = 0x2

前端之家收集整理的这篇文章主要介绍了android – 二进制XML文件行#17:由UnsupportedOperationException引起的冒充类错误:无法转换为维:type = 0x2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在试图运行我的应用程序( 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_width="match_parent"
    android:layout_height="48dp"
    android:background="@drawable/list_selector">
    <ImageView android:id="@+id/icon"   
        android:layout_width="25dp"
        android:layout_height="wrap_content"
        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_width="wrap_content"
        android:layout_height="match_parent"
        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_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true" 
        android:text="2" 
        android:layout_marginRight="8dp" 
        android:textColor="#959595"/>
</RelativeLayout>

希望有人可以帮助我提前致谢.

解决方法

xml中的错误
检查您是否在您提交的第17行.

机器人:ATTR / textAppearanceListItemSmall如果这里的错误是清单中的api级别更改

猜你在找的Android相关文章