Solved

android animation wont start

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
smart phone memory and app 3 71
Transfer Blackberry Contact to Andriod 2 64
Password Keeper for Andriod 5 65
Removing Gmail Contacts From Samsung Tab 2 74
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
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.
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.
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…

895 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

15 Experts available now in Live!

Get 1:1 Help Now