我的动画Drawable中的奇怪错误

时间:2013-12-31 22:25:03

标签: java android xml eclipse logcat

尝试启动Activity时出现奇怪错误。

我认为Animation Drawable

中的错误

logcat的:

    12-31 06:37:45.138: E/AndroidRuntime(922): FATAL EXCEPTION: main
    12-31 06:37:45.138: E/AndroidRuntime(922): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MalekAlrwily.BasicVaccinations/com.MalekAlrwily.BasicVaccinations.Main}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.os.Handler.dispatchMessage(Handler.java:99)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.os.Looper.loop(Looper.java:137)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.ActivityThread.main(ActivityThread.java:5103)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at java.lang.reflect.Method.invokeNative(Native Method)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at java.lang.reflect.Method.invoke(Method.java:525)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at dalvik.system.NativeStart.main(Native Method)
    12-31 06:37:45.138: E/AndroidRuntime(922): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.Activity.setContentView(Activity.java:1895)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at com.MalekAlrwily.BasicVaccinations.Main.onCreate(Main.java:15)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.Activity.performCreate(Activity.java:5133)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    12-31 06:37:45.138: E/AndroidRuntime(922):  ... 11 more
    12-31 06:37:45.138: E/AndroidRuntime(922): Caused by: java.lang.reflect.InvocationTargetException
    12-31 06:37:45.138: E/AndroidRuntime(922):  at java.lang.reflect.Constructor.constructNative(Native Method)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.LayoutInflater.createView(LayoutInflater.java:594)
12-31 06:37:45.138: E/AndroidRuntime(922):  ... 23 more
    12-31 06:37:45.138: E/AndroidRuntime(922): Caused by: java.lang.OutOfMemoryError
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.content.res.Resources.loadDrawable(Resources.java:2105)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.content.res.Resources.getDrawable(Resources.java:695)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.content.res.Resources.loadDrawable(Resources.java:2087)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.View.<init>(View.java:3364)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.View.<init>(View.java:3293)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.view.ViewGroup.<init>(ViewGroup.java:453)
    12-31 06:37:45.138: E/AndroidRuntime(922):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:242)
    12-31 06:37:45.138: E/AndroidRuntime(922):  ... 26 more

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true"
android:background="@drawable/animation"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Main" >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@android:color/transparent"
        android:onClick="onClick"
        android:src="@drawable/next" />

</RelativeLayout>

AnimationDrawable

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item  android:drawable="@drawable/begin1" android:duration="3000" />
    <item  android:drawable="@drawable/begin2" android:duration="3000" />
    <item  android:drawable="@drawable/begin3" android:duration="3000" />
    <item  android:drawable="@drawable/begin4" android:duration="3000" />
    <item  android:drawable="@drawable/begin5" android:duration="3000" />
    <item  android:drawable="@drawable/begin6" android:duration="3000" />
    <item  android:drawable="@drawable/begin7" android:duration="3000" />
    <item  android:drawable="@drawable/begin8" android:duration="3000" />
    <item  android:drawable="@drawable/begin9" android:duration="3000" />
</animation-list>

2 个答案:

答案 0 :(得分:0)

看起来动画可绘制定义中的任何内容都有太多的内存来解码和排序。这个想法是它加载所有项目并将它们放在一个数组中,并根据为每个帧指定的时间将它们交换进场景。

如果这一切都无法适应内存,那么使用某种处理程序或更好地自己做这件事可能会更好,但只需在相应的图像中编码具有指定帧的电影,并通过视频播放动画编解码器。

答案 1 :(得分:0)

试试这个..

您的可绘制图像可能太大。你应该减少图像的大小。