Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSteve Hunter
57,712 PointsNullPointerException in animateCrystalBall()
I'm having difficulties with code that previously worked just fine and that I've not changed! I assume the problem may lie elsewhere.
However, LogCat is giving me the following errors:
05-18 06:41:17.801: E/AndroidRuntime(1254): FATAL EXCEPTION: main 05-18 06:41:17.801: E/AndroidRuntime(1254): Process: uk.co.bigdogconsultants.crystalball, PID: 1254 05-18 06:41:17.801: E/AndroidRuntime(1254): java.lang.NullPointerException 05-18 06:41:17.801: E/AndroidRuntime(1254): at uk.co.bigdogconsultants.crystalball.MainActivity.animateCrystalBall(MainActivity.java:49) 05-18 06:41:17.801: E/AndroidRuntime(1254): at uk.co.bigdogconsultants.crystalball.MainActivity.access$2(MainActivity.java:47) 05-18 06:41:17.801: E/AndroidRuntime(1254): at uk.co.bigdogconsultants.crystalball.MainActivity$1.onClick(MainActivity.java:40)
Line 40 is the call to the animateCrystalBall method Line 47 is the declaration/definition of the method and Line 49 is
mCrystalBallImage.setImageResource(R.drawable.ball_animation);
I can't see anything wrong with that. The
ball_animation.xml
file is there unaltered so I'm not sure what is pointed at that is Null.
Any ideas?
Thanks.
2 Answers
Anthony H
2,515 PointsPost your log cat file and source @ pastebin.com/ then we can look at the code/files you're have problems with ;)
Steve Hunter
57,712 PointsThis self-fixed somehow. I can't replicate the problem and the animation works fine!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsAnd if I comment out the call to the method everything works fine just without the animation, obviously!