0

我得到了一个 AndroidRunTime 错误,不知道我做错了什么。如果我尝试从一项活动转到下一项活动,则会出现问题。如果我启动应用程序一切正常,我可以从一项活动更改为下一项活动。但是一段时间后它停止工作,虽然活动非常相似......

日志猫:

        Tag: AndroidRunTime

        FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.moja.wbf/com.moja.wbf.GL}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.os.Handler.dispatchMessage(Handler.java:99)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.os.Looper.loop(Looper.java:137)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.ActivityThread.main(ActivityThread.java:5041)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at java.lang.reflect.Method.invokeNative(Native Method)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at java.lang.reflect.Method.invoke(Method.java:511)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at dalvik.system.NativeStart.main(Native Method)
    09-05 08:15:49.681: E/AndroidRuntime(815): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.Activity.setContentView(Activity.java:1881)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at com.moja.wbf.GL.onCreate(GL.java:13)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.Activity.performCreate(Activity.java:5104)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    09-05 08:15:49.681: E/AndroidRuntime(815):  ... 11 more
    09-05 08:15:49.681: E/AndroidRuntime(815): Caused by: java.lang.reflect.InvocationTargetException
    09-05 08:15:49.681: E/AndroidRuntime(815):  at java.lang.reflect.Constructor.constructNative(Native Method)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
    09-05 08:15:49.681: E/AndroidRuntime(815):  ... 23 more
    09-05 08:15:49.681: E/AndroidRuntime(815): Caused by: java.lang.OutOfMemoryError
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.content.res.Resources.loadDrawable(Resources.java:1965)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.View.<init>(View.java:3330)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.View.<init>(View.java:3259)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.view.ViewGroup.<init>(ViewGroup.java:425)
    09-05 08:15:49.681: E/AndroidRuntime(815):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:210)
    09-05 08:15:49.681: E/AndroidRuntime(815):  ... 26 more

XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/eins" >

    <Button
        android:id="@+id/button1"
        android:layout_width="150dp"
        android:layout_height="75dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="60dp"
        android:background="@drawable/button"
        android:onClick="Zwei"
        android:text="WEITER" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_above="@+id/button1"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="44dp"
        android:layout_marginLeft="22dp"
        android:src="@drawable/Rad" />

</RelativeLayout>
4

1 回答 1

0

我认为这是OutOfMemoryError因为您的图像而发生的。实际图像size无关紧要,但尺寸很重要。

示例: aJPEG未压缩时,为每个像素分配 24 位(相应地为红色、绿色和蓝色分配 8 位)。因此,如果我们以一张 1920x1080 的图像为例:1920px*1080px*24bit / 1024(KB) / 1024(MB) / 8(bits in byte) = appox. 每个图像分配 6 MB 的内存。使用其中许多会导致堆溢出。

除此之外,AndroidBitmapFactory在解码大图像(以像素为“大”)时往往会失败,因此建议检查您Bitmap的尺寸并适当缩小它。周围有很多示例,请查看有关此主题的官方文档。

于 2014-09-05T09:07:52.093 回答