0

添加启动画面后,我的应用程序崩溃。下面是错误日志、xml 和 java 文件。我在其他应用程序中大多使用相同的代码,但我不明白为什么它在这里不起作用请帮助

04-09 20:36:05.469: E/AndroidRuntime(27529): FATAL EXCEPTION: main
04-09 20:36:05.469: E/AndroidRuntime(27529): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zaidi.mindmapmaker/com.behram.mindmapmaker.SplashScreen}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.os.Looper.loop(Looper.java:137)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.main(ActivityThread.java:4424)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at dalvik.system.NativeStart.main(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.Activity.setContentView(Activity.java:1835)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.behram.mindmapmaker.SplashScreen.onCreate(SplashScreen.java:18)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.Activity.performCreate(Activity.java:4465)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-09 20:36:05.469: E/AndroidRuntime(27529):    ... 11 more
04-09 20:36:05.469: E/AndroidRuntime(27529): Caused by: java.lang.reflect.InvocationTargetException
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Constructor.constructNative(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
04-09 20:36:05.469: E/AndroidRuntime(27529):    ... 24 more
04-09 20:36:05.469: E/AndroidRuntime(27529): Caused by: java.lang.OutOfMemoryError
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.content.res.Resources.loadDrawable(Resources.java:1935)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.widget.ImageView.<init>(ImageView.java:119)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.widget.ImageView.<init>(ImageView.java:109)
04-09 20:36:05.469: E/AndroidRuntime(27529):    ... 27 more

splash_screen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

</LinearLayout>

闪屏.java

public class SplashScreen extends Activity {

// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;

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

    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, ActivityB.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

}

4

2 回答 2

0

引起:java.lang.OutOfMemoryError

您需要缩小图像。它占用太多空间导致OOM。我认为从 api 3.0 开始,位图像素数据存储在堆上。

位图内存不足错误

引用文档

如果您的应用程序已达到堆容量并尝试分配更多内存,它将收到 OutOfMemoryError。

检查加载图像是否有效@

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

还要检查

检查这个

https://developer.android.com/training/displaying-bitmaps/manage-memory.html

于 2014-04-09T15:46:04.080 回答
0

该错误是由java.lang.OutOfMemoryError引起的

这取决于您的位图有多大,当您在计算机上读取大小时,Android 似乎分配的空间比图像的大小多一点。所以...

  • 您可以只使用较小的图像。
  • Google 实际上已经在此处发布了关于避免 OutOfMemoryErrors 的指南,这将有很大帮助,尽管我也必须使用较小的图像尺寸。
  • 几乎肯定会起作用的一种方法是在清单中的应用程序标记之间设置 android:largeHeap="true" 。这会增加您的堆大小,但可能会使您的应用程序稍微滞后。

也许对你来说,这些想法的结合会奏效。

请参阅此链接以有效显示位图

或者

以编程方式将图像添加到图像视图

 if(imageView != null) {
    ((BitmapDrawable)imageView.getDrawable()).getBitmap().recycle();
    imageView = (ImageView) view.findViewById(R.id.imageView);
    imageView.setImageResource(resID);
}
else {
    imageView = (ImageView) view.findViewById(R.id.imageView);
    imageView.setImageResource(resID);
}
于 2014-04-09T15:52:05.933 回答