1

I'm developing a tour guide app. I'm using animation list to appear some images in sequence. But I'm getting outofMemory Error. This is my logcat.

08-14 17:29:15.240: E/AndroidRuntime(20670):
java.lang.OutOfMemoryError 08-14 17:29:15.240:
E/AndroidRuntime(20670):    at
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 08-14
17:29:15.240: E/AndroidRuntime(20670):  at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
08-14 17:29:15.240: E/AndroidRuntime(20670):    at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
08-14 17:29:15.240: E/AndroidRuntime(20670):    at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
08-14 17:29:15.240: E/AndroidRuntime(20670):    at
android.content.res.Resources.loadDrawable(Resources.java:2988) 08-14
17:29:15.240: E/AndroidRuntime(20670):  at
android.content.res.Resources.getDrawable(Resources.java:1558) 08-14
17:29:15.240: E/AndroidRuntime(20670):  at
android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
08-14 17:29:15.240: E/AndroidRuntime(20670):    at
android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
08-14 17:29:15.240: E/AndroidRuntime(20670):    at
android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
08-14 17:29:15.240: E/AndroidRuntime(20670):    at
android.content.res.Resources.loadDrawable(Resources.java:2970) 08-14
17:29:15.240: E/AndroidRuntime(20670):  at
android.content.res.Resources.getDrawable(Resources.java:1558) 08-14
17:29:15.240: E/AndroidRuntime(20670):  at
android.view.View.setBackgroundResource(View.java:15697)

This is my code.

public class Mahadewalaya extends FragmentActivity implements LocationListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maha_dewalaya);

        ImageView iv=(ImageView) findViewById(R.id.imageView_mahaDewalaya);
        iv.setBackgroundResource(R.drawable.animation_dewalaya);//animation.xml reference here
        iv.setScaleType(ScaleType.FIT_CENTER);
        final AnimationDrawable frameAnimation = (AnimationDrawable) iv.getBackground();

        if(frameAnimation.isRunning()){
                    frameAnimation.stop();
                }else{  
                    frameAnimation.stop();
                    frameAnimation.start();
                }
}

This is the relevant layout file.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView_mahaDewalaya"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            android:contentDescription="@string/imageVw" />
</LinearLayout>
</ScrollView>

This is the animation list.

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >

     <item
        android:drawable="@drawable/mahadewalaya_main"
        android:duration="10000"/>

    <item
        android:drawable="@drawable/dewalaya"
        android:duration="8500"/>


   <item
        android:drawable="@drawable/botree_dewalaya"
        android:duration="8500"/>
      <item
        android:drawable="@drawable/j"
        android:duration="8500"/>
       <item
        android:drawable="@drawable/manik_river"
        android:duration="8500"/>


</animation-list>

Please help me with this. Thanks in advance. Do I have to implement any class in order to overcome this error?

1 Answer 1

0

You need to set images from code. You should create single bitmap, set image to it and show it to the user. From time to time you can change current image to another.

1
  • Thanks for the reply. Now only I understood the thing.Thanks again Aug 27, 2014 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.