Solved

android animation wont start

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loading Viber backup taken on Android to an iOS mobile phone 5 111
Android - Custom Control Creation 2 41
Google Maps 6 42
Delphi android app hide keyboard 3 45
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…

733 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