添加启动画面后我的应用程序崩溃了。下面是错误日志,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>
SplashScreen.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);
}
}
答案 0 :(得分:0)
引起:java.lang.OutOfMemoryError
您需要缩小图像。它占据了太多导致OOM的空间。我认为从api 3.0开始,位图像素数据存储在堆上。
Out of Memory error with Bitmap
引用文档
如果您的应用已达到堆容量并尝试分配更多 内存,它将收到一个OutOfMemoryError。
有效地检查加载图像@
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
同时检查
检查
https://developer.android.com/training/displaying-bitmaps/manage-memory.html
答案 1 :(得分:0)
错误是由 java.lang.OutOfMemoryError
引起的这取决于您的位图有多大,当您在计算机上读取大小时,Android似乎会分配比图像大小更多的空间。所以......
也许对你而言,这些想法的组合将起作用。
请参阅此Link for Displaying Bitmaps Efficiently
或强>
以编程方式将图像添加到图像视图
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);
}