Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (retired 2014) Pretty Little Things Animating the Crystal Ball

ball_animation cannot be resolved or is not a field

When I put my code in Eclipse, ball_animation is not an acceptable field. The other ball images are not being seen either. Below is the code. Please help!!!

    private void animateCrystalBall() {
        ImageView crystalBallImage = (ImageView) findViewById(R.id.imageView1);
        crystalBallImage.setImageResource(R.drawable.ball_animation);
        AnimationDrawable ballAnimation = (AnimationDrawable) crystalBallImage.getDrawable();
        if (ballAnimation.isRunning()) {
            ballAnimation.stop();
        }
        ballAnimation.start();
    }

5 Answers

I'll give it a go Timothy. Unfortunately though when I tried this last night (removing the files, re-adding them & removing imports/re-adding them with Command+O) the errors that I got were horrendous. The code looked like a suicidal hemophiliac even after replacing my code with the ones in the zip file.

I'm just going to start over, make sure that eclipse is up-dated in all areas and see what happens. Last swing for this at bat.

Timothy Boland
Timothy Boland
18,237 Points

Yes, when importing other peoples projects into Eclipse, you never know what errors you're going to get...it depends on the project and your current setup....But DONT QUIT....this is just one of the pitfalls...its best to just Google each error you get...and make the recommended adjustments for each...the best results are usually from StackOverflow...and as you get more practice...you will start recognizing the errors and know what to do...For me personally, i didn't want these errors to get in the way of my learning, so instead of importing the attached projects in the lesson, i just code each lesson into my own project by hand....its better practice that way.

Paul Stevens
Paul Stevens
4,125 Points

Hello, not sure if I can help, but I will give it a go. :)

Try looking in the res/drawable-mdpi folder. That is where we put our ball_animation.xml. Check that the file name ball_animation.xml doesn't have a spelling mistake in it's name. Other than that I am not sure, but I will paste my ball_animation.xml file for you incase that helps at all.

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true" >

    <item
        android:drawable="@drawable/ball01"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball02"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball03"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball04"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball05"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball06"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball07"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball08"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball09"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball10"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball11"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball12"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball13"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball14"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball15"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball16"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball17"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball18"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball19"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball20"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball21"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball22"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball23"
        android:duration="41"/>
    <item
        android:drawable="@drawable/ball24"
        android:duration="41"/>

    <!-- Reset to original -->
    <item
        android:drawable="@drawable/ball01"
        android:duration="10"/>

</animation-list>

Hope this helps. :D

Thanks Paul,

I appreciate this but unfortunately this doesn't help since we copied the filed from a zip and dragged it into the folder. I did check just to make sure and there were no spelling mistakes (which is unusual for me).

I will paste a screenshot if someone can tell me how without having to upload it to a third party server.

Timothy Boland
Timothy Boland
18,237 Points

this is a common problem in eclipse when you import a project instead of creating it from scratch...try removing the imports and hit Ctrl+O and have them reloaded.