Solved

android animation wont start

Posted on 2010-11-23
2
859 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
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…

734 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