• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps getAnimation().setAnimationListener causes NullPointerException

The7even

Lurker
Hi guys, I have a ProgressBar and I'm trying to use the setAnimationListener to listen for when the animation ends and etc..

the problem is, it gives me a null pointer exception when I run the code... and I know why NPE's occur.. but with this, it doesn't make much sense.

My code is the following

Code:
pb = (ProgressBar)findViewById(R.id.progressBar1);
		
		pb.getAnimation().setAnimationListener(new AnimationListener(){

			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
		});


Can anyone explain why this is throwing a nullpointerexception?

As soon as I delete the setAnimationListener(new AnimationListener etc...)

no errors occur.

It doesn't make sense to me.
 
Back
Top Bottom