如何解决:java.lang.RuntimeException:无法启动活动ComponentInfo / android.view.InflateException

时间:2023-01-24 20:53:18

I get the following exception when I launch my activity.

我启动活动时遇到以下异常。

11-16 13:44:17.893: E/AndroidRuntime(27027): FATAL EXCEPTION: main
11-16 13:44:17.893: E/AndroidRuntime(27027): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bluesky.smartpolice2/com.bluesky.smartpolice.FrontActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.ActivityThread.access$700(ActivityThread.java:150)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.os.Looper.loop(Looper.java:137)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.ActivityThread.main(ActivityThread.java:5279)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at java.lang.reflect.Method.invokeNative(Native Method)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at java.lang.reflect.Method.invoke(Method.java:511)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at dalvik.system.NativeStart.main(Native Method)
11-16 13:44:17.893: E/AndroidRuntime(27027): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:342)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.Activity.setContentView(Activity.java:1928)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at com.bluesky.smartpolice.FrontActivity.onCreate(FrontActivity.java:20)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.Activity.performCreate(Activity.java:5267)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
11-16 13:44:17.893: E/AndroidRuntime(27027):    ... 11 more
11-16 13:44:17.893: E/AndroidRuntime(27027): Caused by: java.lang.reflect.InvocationTargetException
11-16 13:44:17.893: E/AndroidRuntime(27027):    at java.lang.reflect.Constructor.constructNative(Native Method)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.view.LayoutInflater.createView(LayoutInflater.java:593)
11-16 13:44:17.893: E/AndroidRuntime(27027):    ... 24 more
11-16 13:44:17.893: E/AndroidRuntime(27027): Caused by: java.lang.OutOfMemoryError
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.content.res.Resources.loadDrawable(Resources.java:2854)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.widget.ImageView.<init>(ImageView.java:126)
11-16 13:44:17.893: E/AndroidRuntime(27027):    at android.widget.ImageView.<init>(ImageView.java:116)
11-16 13:44:17.893: E/AndroidRuntime(27027):    ... 27 more

===========================================================

But my FrontActivity contains just one imageview. Please help me... What's wrong with my source?

但我的FrontActivity只包含一个imageview。请帮帮我...我的来源有什么问题?

It's my java source.

这是我的java源码。

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class FrontActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_front);

        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent i = new Intent(FrontActivity.this, DetailActivity.class);
                startActivity(i);
                finish();
            }
        }, 2000);
    }
}

And it's my xml.

这是我的xml。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".FrontActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/front" />

</LinearLayout>

1 个解决方案

#1


0  

You seem to be getting OutOfMemoryError, which mean the image you have in ImageView seems to be very large. Try decreasing the size of it.

你似乎得到OutOfMemoryError,这意味着你在ImageView中的图像似乎非常大。尝试减小它的大小。

#1


0  

You seem to be getting OutOfMemoryError, which mean the image you have in ImageView seems to be very large. Try decreasing the size of it.

你似乎得到OutOfMemoryError,这意味着你在ImageView中的图像似乎非常大。尝试减小它的大小。