我有一个闪屏,显示 2 秒的图像。该图像是PNG图像。当我启动我的应用程序时,有时它会崩溃并显示以下错误消息。我的应用程序崩溃的确切行是 setContentView(R.layout.splash);
关键错误行:我可以看到在扩展布局时参考 java.lang.OutOfMemoryError 有一些错误
你能告诉我我需要在哪里更正我的代码吗?
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash">
</RelativeLayout>
Java 代码:
public class Splash extends Activity{
@Override
protected void onCreate(Bundle GoOnSudha) {
// TODO Auto-generated method stub
super.onCreate(GoOnSudha);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
Thread thread = new Thread(){
public void run(){
try{
sleep(2000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent dragDropIntent = new Intent("android.intent.action.DRAGDROP");
startActivity(dragDropIntent);
}
}
};
thread.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
日志猫:
05-04 19:34:05.651: E/AndroidRuntime(28305): FATAL EXCEPTION: main
05-04 19:34:05.651: E/AndroidRuntime(28305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.DragDrop/com.example.DragDrop.Splash}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.ActivityThread.access$600(ActivityThread.java:127)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.os.Looper.loop(Looper.java:137)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.ActivityThread.main(ActivityThread.java:4441)
05-04 19:34:05.651: E/AndroidRuntime(28305): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 19:34:05.651: E/AndroidRuntime(28305): at java.lang.reflect.Method.invoke(Method.java:511)
05-04 19:34:05.651: E/AndroidRuntime(28305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
05-04 19:34:05.651: E/AndroidRuntime(28305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
05-04 19:34:05.651: E/AndroidRuntime(28305): at dalvik.system.NativeStart.main(Native Method)
05-04 19:34:05.651: E/AndroidRuntime(28305): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
05-04 19:34:05.651: E/AndroidRuntime(28305): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-04 19:34:05.651: E/AndroidRuntime(28305): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.Activity.setContentView(Activity.java:1835)
05-04 19:34:05.651: E/AndroidRuntime(28305): at com.example.DragDrop.Splash.onCreate(Splash.java:18)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.Activity.performCreate(Activity.java:4465)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
05-04 19:34:05.651: E/AndroidRuntime(28305): ... 11 more
05-04 19:34:05.651: E/AndroidRuntime(28305): Caused by: java.lang.reflect.InvocationTargetException
05-04 19:34:05.651: E/AndroidRuntime(28305): at java.lang.reflect.Constructor.constructNative(Native Method)
05-04 19:34:05.651: E/AndroidRuntime(28305): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
05-04 19:34:05.651: E/AndroidRuntime(28305): ... 23 more
05-04 19:34:05.651: E/AndroidRuntime(28305): Caused by: java.lang.OutOfMemoryError
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.Bitmap.nativeCreate(Native Method)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:530)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:505)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:357)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:777)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.content.res.Resources.loadDrawable(Resources.java:1940)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.View.<init>(View.java:2844)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.View.<init>(View.java:2781)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.view.ViewGroup.<init>(ViewGroup.java:412)
05-04 19:34:05.651: E/AndroidRuntime(28305): at android.widget.RelativeLayout.<init>(RelativeLayout.java:179)
05-04 19:34:05.651: E/AndroidRuntime(28305): ... 26 more