Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:27:38+00:00 2026-05-26T00:27:38+00:00

I am trying to get this example working: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html but as it starts, it

  • 0

I am trying to get this example working:
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

but as it starts, it crashes (force closes) and I am not really sure where the problem is as I am new to this.

My code:
(Java file)

package com.ryan.test;

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

public class TestAnimationActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);            

        ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
        img.setBackgroundResource(R.drawable.spin_animation);    
        AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();    
        frameAnimation.start();            
        setContentView(R.layout.main);
    }
}

Animation XML file

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
 android:oneshot="false">
    <item android:drawable="@drawable/note0" android:duration="50" />
    <item android:drawable="@drawable/note1" android:duration="50" />        
 </animation-list>

Main.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />

    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/note0"
        android:id="@+id/spinning_wheel_image"></ImageView>
</LinearLayout>

Note that the animation xml file is in res/drawable-hdpi, putting it in the res/anim folder was giving me errors. Also note I am an Android noobie 😉

Thanks!
Ryan

EDIT;

There IS a bug in the demo code: http://code.google.com/p/android/issues/detail?id=1818
so i modified the code: pastebin.com/ZtLf8J87
and it works 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:27:39+00:00Added an answer on May 26, 2026 at 12:27 am

    The animation xml should always decide in res/anim. The reason it is throwing an error is due to the fact that you are using ImageView img =

    (ImageView)findViewById(R.id.spinning_wheel_image);

    before setting the content view i.e

    setContentView(R.layout.main);

    For tracking the errors and debugging use Logcat.You may find that in Eclipse at following location. Windows => Open Perspective => Logcat

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I am working from this example: http://jqueryui.com/demos/tabs/ and trying to get the tabs to
I'm trying to get this simple PowerShell script working, but I think something is
I'm trying to get the jstree plugin working, following the Predefined HTML example on
I'm trying to get this sample for AJAX to WCF working, with the following
I'm trying to get this piece of code working a little better. I suspect
I'm trying to get this sitemap clas s working. It appears to use LINQ,
I am trying to get this awesome JQuery plugin working with SQL Server. I
I'm trying to get a simple example working using gSoap, for VS2008. I've done
I've been trying to get this really simple example of using AJAX with JQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.