Solved

android animation wont start

Posted on 2010-11-23
2
852 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I tend toward trying the newest hardware and software.  Thiss sometimes works out to my benefit, and sometimes not.  Because I downloaded and installed Android 5.x (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.htm…
A short article about problems I had with the new location API and permissions in Marshmallow
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.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

831 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