Solved

android animation wont start

Posted on 2010-11-23
2
844 Views
Last Modified: 2012-05-10
Im trying to run an android animation in eclipse but always get debugger error
everything compiles until you add the line that actually runs the whole thing..
spaceshipImage.startAnimation(hyperspaceJumpAnimation);
 I have put the code in a try/catch and get the error msg java.lang.NullPointerException

here is the code for SpaceJump.java:


at this point im not so interested in what the animation does, just getting an animation running really.  
any help is grealty appreciated..

public void onCreate(Bundle savedInstanceState) { try{

    ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);
    Animation hyperspaceJumpAnimation =AnimationUtils.loadAnimation(this,           R.anim.jump1);
    spaceshipImage.startAnimation(hyperspaceJumpAnimation);    
    }catch(Exception e){
    Log.v(TAG,"ERROR "+e.toString()+"\nPart2 "+e.getMessage());
    }

and myjump1.xml//this is all taken from andorid developers site though so shoud be all ok
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
   	 android:shareInterpolator="false">
   <scale
          android:interpolator="@android:anim/accelerate_decelerate_interpolator"
          android:fromXScale="1.0"
          android:toXScale="1.4"
          android:fromYScale="1.0"
          android:toYScale="0.6"
          android:pivotX="50%"
          android:pivotY="50%"
          android:fillAfter="false"
          android:duration="700" />
   <set android:interpolator="@android:anim/decelerate_interpolator">
      <scale
             android:fromXScale="1.4" 
             android:toXScale="0.0"
             android:fromYScale="0.6"
             android:toYScale="0.0" 
             android:pivotX="50%" 
             android:pivotY="50%" 
             android:startOffset="700"
             android:duration="400" 
             android:fillBefore="false" />
      <rotate 
             android:fromDegrees="0" 
             android:toDegrees="-45"
             android:toYScale="0.0" 
             android:pivotX="50%" 
             android:pivotY="50%"
             android:startOffset="700"
             android:duration="400" />
   </set>
</set>

Open in new window

0
Comment
Question by:GCF1
2 Comments
 
LVL 8

Accepted Solution

by:
Arabia_vn earned 500 total points
ID: 34202423
I think the problem is that you haven't defined "spaceshipImage" yet, so this will find nothing.

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

And another thing, don't depend on debugging when you code Android, use lo
gging instead and you should see where exactly the problem comes from.
0
 
LVL 5

Expert Comment

by:UnConn
ID: 34259018
As said above, there is no ID in your XML that is spaceshipimage.  What is it going to change/display?  I am also not sure I would do animation this way.  I would look at canvas, surfaceview, or even tweening.

http://developerlife.com/tutorials/?p=343
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now