Android模拟器错误

时间:2012-04-01 08:31:50

标签: android android-emulator bitmap android-2.2-froyo

我已经使用Android 2.2成功在系统中执行了一个项目......

当我在其他系统中运行项目时,使用相同的配置和模拟器选项,它会崩溃......

错误日志显示:

  

java.lang.RuntimeException:无法启动活动ComponentInfo {com.myabc / com.myabc.Screen}:android.view.InflateException:二进制XML文件行#11:错误导致类

任何人都可以为我提供一个解决方案,因为它是一个严肃的解决方案,可以在其他系统中调试...

xml im inflating是:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splashback" 
>
 <ImageView android:id="@+id/img6" android:src="@drawable/splash71" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_x="0dip" android:layout_y="0dip"></ImageView>
 <ImageView android:id="@+id/img5" android:src="@drawable/splash5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_x="0dip" android:layout_y="0dip"></ImageView>
 <ImageView android:id="@+id/img4" android:src="@drawable/splash4" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_x="0dip" android:layout_y="0dip"></ImageView>
 <ImageView android:id="@+id/img3" android:src="@drawable/splash3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_x="0dip" android:layout_y="0dip"></ImageView>
 <ImageView android:id="@+id/img2" android:src="@drawable/splash2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_x="0dip" android:layout_y="0dip"></ImageView>
 <ImageView android:id="@+id/img1" android:src="@drawable/splash1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_x="0dip" android:layout_y="0dip"></ImageView>
 <ImageView android:layout_width="wrap_content"  android:layout_height="wrap_content" android:id="@+id/img0" android:src="@drawable/screen8" android:layout_x="0dp" android:layout_y="0dp"></ImageView>
</AbsoluteLayout>

完整的堆栈跟踪说:

04-01 10:41:57.475: E/AndroidRuntime(430): FATAL EXCEPTION: main
04-01 10:41:57.475: E/AndroidRuntime(430): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myabc/com.myabc.Screen}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.os.Looper.loop(Looper.java:123)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-01 10:41:57.475: E/AndroidRuntime(430):  at java.lang.reflect.Method.invokeNative(Native Method)
04-01 10:41:57.475: E/AndroidRuntime(430):  at java.lang.reflect.Method.invoke(Method.java:521)
04-01 10:41:57.475: E/AndroidRuntime(430):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-01 10:41:57.475: E/AndroidRuntime(430):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-01 10:41:57.475: E/AndroidRuntime(430):  at dalvik.system.NativeStart.main(Native Method)
04-01 10:41:57.475: E/AndroidRuntime(430): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-01 10:41:57.475: E/AndroidRuntime(430):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-01 10:41:57.475: E/AndroidRuntime(430):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.Activity.setContentView(Activity.java:1647)
04-01 10:41:57.475: E/AndroidRuntime(430):  at com.myabc.Screen.onCreate(Screen.java:29)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-01 10:41:57.475: E/AndroidRuntime(430):  ... 11 more
04-01 10:41:57.475: E/AndroidRuntime(430): Caused by: java.lang.reflect.InvocationTargetException
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.widget.ImageView.<init>(ImageView.java:108)
04-01 10:41:57.475: E/AndroidRuntime(430):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-01 10:41:57.475: E/AndroidRuntime(430):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-01 10:41:57.475: E/AndroidRuntime(430):  ... 22 more
04-01 10:41:57.475: E/AndroidRuntime(430): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.Bitmap.nativeCreate(Native Method)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.content.res.Resources.loadDrawable(Resources.java:1709)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-01 10:41:57.475: E/AndroidRuntime(430):  at android.widget.ImageView.<init>(ImageView.java:118)

3 个答案:

答案 0 :(得分:3)

  

引起:java.lang.OutOfMemoryError:位图大小超过VM预算

你使用的内存太多了。在布局中降低图片的分辨率(通过缩放图像文件;而不是通过更改图像视图大小),然后重试。

另外请从不使用AbsoluteLayout,它已被弃用,您将在许多设备上遇到麻烦。

答案 1 :(得分:3)

你得到了OutOfMemoryError:bitmap size exceeds VM budget。您尝试用于ImageViews的位图似乎占用了大量内存。最好是在获取图像的位置保留较亮的图像文件(通过降低分辨率来缩小它们)。一种不太优选的方法是在内存中逐个压缩图像并每次都回收()。

 private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
                                    int quality) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            src.compress(format, quality, os);

            byte[] array = os.toByteArray();
            return BitmapFactory.decodeByteArray(array, 0, array.length);
        }

请参阅http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.html

上的此示例

答案 2 :(得分:2)

如果你使用任何其他布局共享完整的xml文件,那么弃用AbsoluteLayout的第一件事会更好,这个文件也会在代码片段中膨胀你在代码中膨胀的方式。