2016-04-20 21 views
0

Ich versuche Rahmenanimation in der App zu haben, die ich für den Unterricht entwerfe, aber die App stürzt immer wieder ab, obwohl ich genau nachgeforscht habe, wie die Frame-Animation aussehen soll. Ist es wahrscheinlicher, dass mein Android-Studio abstürzt oder der Code falsch ist?Frame-Animation funktioniert nicht

<item android:drawable="@drawable/archerclip1" android:duration="100"/> 
<item android:drawable="@drawable/archerclip2" android:duration="100"/> 
<item android:drawable="@drawable/archerclip3" android:duration="100"/> 
<item android:drawable="@drawable/archerclip4" android:duration="100"/> 

import android.app.Activity; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 

public class FrameAnimation extends Activity { 

AnimationDrawable archerAnimation; 

@Override 

    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_frame_animation); 

    Button btnStart = (Button)findViewById(R.id.btnStart); 

    Button btnStop = (Button)findViewById(R.id.btnStop); 

    ImageView imgFrameAnimation = (ImageView)findViewById(R.id.imgFrameAnimation); 

    imgFrameAnimation.setBackgroundResource(R.drawable.animationone); 

    archerAnimation = (AnimationDrawable)imgFrameAnimation.getBackground(); 

    btnStart.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      archerAnimation.start(); 
     } 
    }); 
    btnStop.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      archerAnimation.stop(); 
     } 
    }); 

    } 

} 


    java.lang.OutOfMemoryError: Failed to allocate a 20232732 byte allocation with 4194304 free bytes and 17MB until OOM 
at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080) 
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635) 
at android.content.res.Resources.loadDrawable(Resources.java:2540) 
at android.content.res.TypedArray.getDrawable(TypedArray.java:870) 
at android.graphics.drawable.AnimationDrawable.inflateChildElements(AnimationDrawable.java:324) 
at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:294) 
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1215) 
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1124) 
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2630) 
at android.content.res.Resources.loadDrawable(Resources.java:2540) 
at android.content.res.Resources.getDrawable(Resources.java:806) 
at android.content.Context.getDrawable(Context.java:458) 
at android.view.View.setBackgroundResource(View.java:17202) 
at edu.wmich.lab5rfoste1057.FrameAnimation.onCreate(FrameAnimation.java:23) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
+0

Bitte fügen Sie Absturzprotokolle hinzu. –

+0

Absturzprotokolle hinzugefügt –

Antwort

0
ImageView imgFrameAnimation = (ImageView)findViewById(R.id.imgFrameAnimation); 

Die Bilder, die Sie sind hier Einstellung sind sehr groß. Versuchen Sie, die Größe auf etwas kleiner zu ändern.

Verwandte Themen