java.lang.RuntimeException:无法启动活动错误膨胀类<unknown> </unknown>

时间:2013-06-05 09:48:58

标签: android runtimeexception inflate-exception

我在Android中做了一个简单的动画应用程序,我在其中使用多个图像来创建布局。应用程序的初始部分工作正常但在调用某些活动后我收到此错误:

06-05 09:14:06.752: E/AndroidRuntime(884): FATAL EXCEPTION: main
06-05 09:14:06.752: E/AndroidRuntime(884): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.WhoWeAreActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.os.Looper.loop(Looper.java:137)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.ActivityThread.main(ActivityThread.java:5039)
06-05 09:14:06.752: E/AndroidRuntime(884):  at java.lang.reflect.Method.invokeNative(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884):  at java.lang.reflect.Method.invoke(Method.java:511)
06-05 09:14:06.752: E/AndroidRuntime(884):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-05 09:14:06.752: E/AndroidRuntime(884):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-05 09:14:06.752: E/AndroidRuntime(884):  at dalvik.system.NativeStart.main(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-05 09:14:06.752: E/AndroidRuntime(884):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-05 09:14:06.752: E/AndroidRuntime(884):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.Activity.setContentView(Activity.java:1881)
06-05 09:14:06.752: E/AndroidRuntime(884):  at com.example.test.WhoWeAreActivity.onCreate(WhoWeAreActivity.java:13)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.Activity.performCreate(Activity.java:5104)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-05 09:14:06.752: E/AndroidRuntime(884):  ... 11 more
06-05 09:14:06.752: E/AndroidRuntime(884): Caused by: java.lang.reflect.InvocationTargetException
06-05 09:14:06.752: E/AndroidRuntime(884):  at java.lang.reflect.Constructor.constructNative(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-05 09:14:06.752: E/AndroidRuntime(884):  ... 24 more
06-05 09:14:06.752: E/AndroidRuntime(884): Caused by: java.lang.OutOfMemoryError
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.widget.ImageView.<init>(ImageView.java:120)
06-05 09:14:06.752: E/AndroidRuntime(884):  at android.widget.ImageView.<init>(ImageView.java:110)
06-05 09:14:06.752: E/AndroidRuntime(884):  ... 27 more

布局文件如下(在名为who_we_are.xml的xml文件中):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <VideoView
        android:id="@+id/VideoView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ImageView
        android:id="@+id/whoweare"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/who_we_are" />

    <ImageView
        android:id="@+id/logo"
        android:layout_width="150dp"
        android:layout_height="30dp"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="25dp"
        android:src="@drawable/sunshinelogo" />

    <ImageView
        android:id="@+id/thought2"
        android:layout_width="250dp"
        android:layout_height="150dp"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="70dp"
        android:src="@drawable/thought2" />

    <RelativeLayout
        android:id="@+id/thumbmenu"
        android:layout_width="173dp"
        android:layout_height="match_parent"
        android:layout_marginTop="250dp"
        android:gravity="left" >

        <ImageView
            android:id="@+id/tab1"
            android:layout_width="100dp"
            android:layout_height="20dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="20dp"
            android:src="@drawable/subtab1" />

        <ImageView
            android:id="@+id/tab2"
            android:layout_width="100dp"
            android:layout_height="20dp"
            android:layout_below="@id/tab1"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="20dp"
            android:src="@drawable/subtab2" />

        <ImageView
            android:id="@+id/tab3"
            android:layout_width="120dp"
            android:layout_height="20dp"
            android:layout_below="@id/tab2"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="27dp"
            android:src="@drawable/subtab3" />

        <ImageView
            android:id="@+id/tab4"
            android:layout_width="100dp"
            android:layout_height="20dp"
            android:layout_below="@id/tab3"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="27dp"
            android:src="@drawable/subtab4" />

        <ImageView
            android:id="@+id/tab5"
            android:layout_width="100dp"
            android:layout_height="20dp"
            android:layout_below="@id/tab4"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="25dp"
            android:src="@drawable/subtab5" />

        <ImageView
            android:id="@+id/tab6"
            android:layout_width="100dp"
            android:layout_height="20dp"
            android:layout_below="@id/tab5"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="15dp"
            android:src="@drawable/subtab6" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/introbg"
        android:layout_width="318dp"
        android:layout_height="381dp"
        android:layout_gravity="right"
        android:layout_marginRight="25dp"
        android:layout_marginTop="25dp"
        android:background="#300000ff"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/introduction "
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="25dp"
            android:paddingTop="25dp"
            android:text="Wo We Are"
            android:textColor="#D8F83F"
            android:textSize="30sp" />

        <TextView
            android:id="@+id/hr "
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="   _________________________________  "
            android:textColor="#D8F83F"
            android:textSize="20sp" />

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <TextView
                android:id="@+id/hr "
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#D8F83F"
                android:textSize="20sp" />
        </ScrollView>
    </LinearLayout>

    <ImageView
        android:id="@+id/belowbar"
        android:layout_width="fill_parent"
        android:layout_height="35dp"
        android:layout_gravity="bottom"
        android:scaleType="fitXY"
        android:src="@drawable/belowbar" />

</FrameLayout>

我在我的java文件中设置了这个布局,这是它的代码(文件名是WhoWeAreActivity.java):

package com.example.test;

import android.app.Activity;
import android.os.Bundle;

public class WhoWeAreActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.who_we_are);
    }

}

我在另一个名为WhoWeAreActivity.java的java文件的click事件上调用CorporateProfileActivity.java,如下所示:

animation = AnimationUtils.loadAnimation(this, R.anim.intro_scale);

ivcp2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp2.startAnimation(animation);
                openWhoWeAre(view);
            }
        });

public void openWhoWeAre(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, WhoWeAreActivity.class);
        startActivity(intent);
    }

此处ivcp2是一个imageview变量。我不知道为什么我会收到这个错误。我是android开发的新手。任何形式的帮助都非常感谢。我一直在寻找过去2天的解决方案,但没有取得任何进展。

2 个答案:

答案 0 :(得分:1)

你的StackTrace指出了以下

 java.lang.OutOfMemoryError

您的设备无法为要在WhoWeAreActivity

中显示的位图分配足够的内存

答案 1 :(得分:1)

你正在加载过大的图片...... 如果从资源加载,您可以手动减小其大小,也可以动态减小大小。 Here is a series of articles应该对此有所帮助。