Eclipse AndroidRunTime错误。我究竟做错了什么?

时间:2014-09-04 09:29:59

标签: android xml eclipse runtime-error android-runtime

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

logcat的:

        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>

1 个答案:

答案 0 :(得分:0)

我认为OutOfMemoryError因图像而发生。实际图像size无关紧要,但尺寸确实如此。

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

除此之外,Android的BitmapFactory有时在解码大图像时会失败(就像素而言“大”),因此建议检查Bitmap的尺寸并适当缩小尺寸。有很多例子,请看一下涵盖这个主题的official documentation