识别LogCat中的错误

时间:2014-04-27 22:41:41

标签: java android logcat

我可以上传我的代码,但我甚至不知道在哪里查找错误。我不确定它在谈论哪个xml文件。任何帮助,将不胜感激。错误如下:

04-27 18:22:26.524: D/AndroidRuntime(15365): Shutting down VM
04-27 18:22:26.524: W/dalvikvm(15365): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
04-27 18:22:26.833: E/AndroidRuntime(15365): FATAL EXCEPTION: main
04-27 18:22:26.833: E/AndroidRuntime(15365): android.view.InflateException: Binary XML file line #18: Error inflating class <unknown>
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at io.uprint.android.adapter.NavDrawerListAdapter.getView(NavDrawerListAdapter.java:47)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.AbsListView.obtainView(AbsListView.java:1598)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.ListView.makeAndAddView(ListView.java:1770)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.ListView.fillDown(ListView.java:693)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.ListView.fillFromTop(ListView.java:750)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.ListView.layoutChildren(ListView.java:1621)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.AbsListView.onLayout(AbsListView.java:1428)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.layout(View.java:7228)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:714)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.layout(View.java:7228)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.layout(View.java:7228)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.layout(View.java:7228)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.layout(View.java:7228)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.layout(View.java:7228)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1145)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.os.Looper.loop(Looper.java:130)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.app.ActivityThread.main(ActivityThread.java:3687)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at java.lang.reflect.Method.invokeNative(Native Method)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at java.lang.reflect.Method.invoke(Method.java:507)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at dalvik.system.NativeStart.main(Native Method)
04-27 18:22:26.833: E/AndroidRuntime(15365): Caused by: java.lang.reflect.InvocationTargetException
04-27 18:22:26.833: E/AndroidRuntime(15365):    at java.lang.reflect.Constructor.constructNative(Native Method)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
04-27 18:22:26.833: E/AndroidRuntime(15365):    ... 36 more
04-27 18:22:26.833: E/AndroidRuntime(15365): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.view.View.<init>(View.java:2118)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.TextView.<init>(TextView.java:383)
04-27 18:22:26.833: E/AndroidRuntime(15365):    at android.widget.TextView.<init>(TextView.java:376)
04-27 18:22:26.833: E/AndroidRuntime(15365):    ... 39 more
04-27 18:22:35.837: I/Process(15365): Sending signal. PID: 15365 SIG: 9

我只是想让支持库用于基本的导航抽屉和操作栏布局。再次感谢。

所以看起来问题就在于你的信息。我认为原因是,这段代码可能没有使用相同的支持库导入。第47行正在进行膨胀。

package io.uprint.android.adapter;

import io.uprint.android.R;
import io.uprint.android.model.NavDrawerItem;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
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);

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

}

下面是布局中的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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:contentDescription="@string/desc_list_item_icon"
        android:src="@drawable/ic_home"
        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="?attr/uprint_listPreferredItemHeightSmall"
        android:textAppearance="?attr/uprint_textAppearanceListItemSmall"
        android:textColor="@color/list_item_title"
        android:gravity="center_vertical"
        android:paddingRight="40dp"/>

    <TextView android:id="@+id/counter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/counter_bg"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="8dp"
        android:textColor="@color/counter_text_color"/>

</RelativeLayout>

不同文件中的属性值 attrs.xml

<declare-styleable name="Theme">

    <!-- Attributes below are needed to support the navigation drawer on Android 3.x. -->
    <!-- A smaller, sleeker list item height. -->
    <attr name="uprint_listPreferredItemHeightSmall" format="dimension" />

    <!-- Drawable used as a background for activated items. -->
    <attr name="uprint_activatedBackgroundIndicator" format="reference" />

    <!-- The preferred TextAppearance for the primary text of small list items. -->
    <attr name="uprint_textAppearanceListItemSmall" format="reference" />

</declare-styleable>

styles.xml值v11:

 <style name="AppBaseTheme" parent="Theme.Light">
        <!-- API 11 theme customizations can go here. -->
         <!-- Implementation of attributes needed for the navigation drawer as the default implementation is based on API-14. -->
          <item name="uprint_listPreferredItemHeightSmall">48dip</item>
          <item name="uprint_textAppearanceListItemSmall">@style/UPrintDrawerMenu</item>
          <item name="uprint_activatedBackgroundIndicator">@drawable/ab_transparent_action_bar</item>
    </style>

     <style name="UPrintDrawerMenu">
          <item name="android:textSize">16sp</item>
          <item name="android:textStyle">bold</item>
          <item name="android:textColor">?android:attr/actionMenuTextColor</item>
      </style>

styles v14 xml:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
    </style>

1 个答案:

答案 0 :(得分:0)

您传递给 NavDrawerListAdapter 的上下文? 我在Gingerbread + AppCompat上遇到了类似的问题,因为我使用的是Application上下文而不是Activity上下文