扩展类<unknown>(ImageView)Honeycomb </unknown>时出错

时间:2014-05-29 16:11:20

标签: android layout

我有这个错误:

05-29 16:58:38.733: E/AndroidRuntime(454): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>

第17行是这一行:

    <ImageView
        android:id="@+id/imageEventCover"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/event_cover"
        android:scaleType="centerCrop" />

我正在尝试在API 12上运行它,它正在崩溃。它适用于API&gt; 14(未在11或13上测试)。

有什么问题?

我的完整xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:inevent="http://schemas.android.com/apk/lib/com.estudiotrilha.inevent.view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingBottom="8dp"
    android:id="@+id/list_events"
    android:addStatesFromChildren="true" >

    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="180dp"
        android:padding="1dp"
        android:background="@drawable/post" >

        <ImageView
            android:id="@+id/imageEventCover"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/event_cover"
            android:scaleType="centerCrop" />

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:visibility="gone"
            android:layout_marginTop="25dp" />

        <com.estudiotrilha.inevent.view.NewTextView
            android:id="@+id/textIsEnrolled"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="ENROLLED"
            android:textColor="@color/infoText"
            inevent:textFor="small"
            android:background="@color/infoBoxRed"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_margin="10dp" />

        <RelativeLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@drawable/event_mark"
            android:layout_marginBottom="12dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp" >

            <com.estudiotrilha.inevent.view.NewTextView 
                android:id="@+id/textEventName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Lisbon Challenge"
                inevent:textFor="h3"
                android:paddingBottom="10dip"/>

            <ImageView
                android:id="@+id/imageCalendar"
                android:layout_below="@+id/textEventName"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:contentDescription="@string/facebookHolder"
                android:src="@drawable/ic_action_go_to_today" />

            <com.estudiotrilha.inevent.view.NewTextView  
                android:id="@+id/textEventDuration"
                android:layout_below="@+id/textEventName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/imageCalendar"
                android:layout_marginLeft="5dp"
                android:textColor="#555"
                inevent:textFor="small"
                android:text="MAI 05-11, 2014" />

            <ImageView
                android:layout_below="@+id/textEventName"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:layout_toLeftOf="@+id/textEventPlace"
                android:contentDescription="@string/facebookHolder"
                android:src="@drawable/ic_action_place" />

            <com.estudiotrilha.inevent.view.NewTextView 
                android:layout_below="@+id/textEventName"
                android:id="@+id/textEventPlace"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="5dp"
                android:textColor="#555"
                inevent:textFor="small"
                android:text="Lisbon, Portugal" />

        </RelativeLayout>
    </RelativeLayout>

    <View android:layout_width="fill_parent"
        android:layout_marginRight="2dp"
        android:layout_marginLeft="2dp"
        android:layout_height="3dp"
        android:background="@drawable/shadow"/>
</LinearLayout>

这是扩展此XML的适配器:

public View getView(int position, View convertView, ViewGroup parent)
{
    ViewHolder holder;

    if(convertView == null)
    {
        convertView = inflater.inflate(R.layout.list_events, null);
        holder = new ViewHolder();

        holder.eventName = (NewTextView) convertView.findViewById(R.id.textEventName);
        holder.eventCoverProgress = (ProgressBar) convertView.findViewById(R.id.progressBar);
        holder.eventDuration = (NewTextView) convertView.findViewById(R.id.textEventDuration);
        holder.eventPlace = (NewTextView) convertView.findViewById(R.id.textEventPlace);
        holder.eventCover = (ImageView) convertView.findViewById(R.id.imageEventCover);
        holder.eventApproved = (NewTextView) convertView.findViewById(R.id.textIsEnrolled);
    }
    else
    {
        holder = (ViewHolder) convertView.getTag();
    }
    ...

这是完整的堆栈跟踪:

05-29 16:58:38.733: E/AndroidRuntime(454): FATAL EXCEPTION: main
05-29 16:58:38.733: E/AndroidRuntime(454): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.createView(LayoutInflater.java:596)
05-29 16:58:38.733: E/AndroidRuntime(454):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
05-29 16:58:38.733: E/AndroidRuntime(454):  at com.estudiotrilha.inevent.adapter.EventsAdapter.getView(EventsAdapter.java:74)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.AbsListView.obtainView(AbsListView.java:1970)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1228)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.ListView.onMeasure(ListView.java:1139)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:764)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
05-29 16:58:38.733: E/AndroidRuntime(454):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1890)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.View.measure(View.java:10828)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewRoot.performTraversals(ViewRoot.java:909)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.view.ViewRoot.handleMessage(ViewRoot.java:2003)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.os.Looper.loop(Looper.java:132)
05-29 16:58:38.733: E/AndroidRuntime(454):  at android.app.ActivityThread.main(ActivityThread.java:4025)
05-29 16:58:38.733: E/AndroidRuntime(454):  at java.lang.reflect.Method.invokeNative(Native Method)
05-29 16:58:38.733: E/AndroidRuntime(454):  at java.lang.reflect.Method.invoke(Method.java:491)
05-29 16:58:38.733: E/AndroidRuntime(454):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-29 16:58:38.733: E/AndroidRuntime(454):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-29 16:58:38.733: E/AndroidRuntime(454):  at dalvik.system.NativeStart.main(Native Method)
05-29 16:58:38.733: E/AndroidRuntime(454): Caused by: java.lang.reflect.InvocationTargetException
05-29 16:58:38.733: E/AndroidRuntime(454):  at java.lang.reflect.Constructor.constructNative(Native Method)
05-29 16:58:38.733: E/AndroidRuntime(454):  at java.lang.reflect.Constructor
05-29 17:03:38.814: I/Process(454): Sending signal. PID: 454 SIG: 9

根据要求,NewTextView:

package com.estudiotrilha.inevent.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.TypedValue;

import com.estudiotrilha.inevent.R;

public class NewTextView extends android.widget.TextView
{
    private String SCHEMA = "http://schemas.android.com/apk/lib/com.estudiotrilha.inevent.view";
    private Context context = null;
    private int textThickness = 4;
    private String textFor = "";

    public NewTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;

        isInEditMode();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NewTextView);

        try {
            try
            {
                textThickness = Integer.parseInt(attrs.getAttributeValue(SCHEMA, "textThickness"));
            } catch(NumberFormatException e)
            {
                textThickness = 4;
            }

            textFor = attrs.getAttributeValue(SCHEMA, "textFor");

            if(textFor == null) textFor = "p";

            setThickness(textThickness);
            setTextUtility(textFor);

            invalidate();
            requestLayout();
        } finally {
            a.recycle();
        }
    }

    private void setThickness(int textThickness)
    {
        Typeface typeface = null;

        switch(textThickness)
        {
        case 0:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_black.ttf");
            break;
        case 1:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_bold.ttf");
            break;
        case 2:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_medium.ttf");
            break;
        case 3:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_regular.ttf");
            break;
        case 4:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_light.ttf");
            break;
        case 5:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_thin.ttf");
            break;
        default:
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_light.ttf");
            break;
        }

        setTypeface(typeface);
    }

    private void setTextUtility(String textFor)
    {
        if(textFor.equals("goku"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 40.0f);
        else if(textFor.equals("h1"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20.0f);
        else if(textFor.equals("h2"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
        else if(textFor.equals("h3"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16.0f);
        else if(textFor.equals("p"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14.0f);
        else if(textFor.equals("small"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12.0f);
        else
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14.0f);
    }
}

2 个答案:

答案 0 :(得分:0)

这是一个记忆问题。

Stacktrace证明了这一点:

05-29 17:23:17.173: E/dalvikvm-heap(527): Out of memory on a 1024016-byte allocation.

答案 1 :(得分:0)

由于

,您收到此错误
android:src="@drawable/event_cover"

event_cover图像的大小非常大。这就是你收到此错误的原因。

解决方案

将您的图片设为KB而不是MB,并在清单文件的应用标记中添加

android:largeheap="true";