In the code below I keep getting a null exception error and have tested to the point to know its coming from the line of code ‘startup_logo.setBackgroundResource(R.anim.startup)’ and more specifically ‘setBackgroundResource.’ I am not sure why this could be happening, could anyone please helpout? Thanks.
protected static AnimationDrawable temp, startup_move, menu_start, featuredpanel_start, collection_start, recommend_start, top_start, random_start;
protected static void startup() {
for (int i = 0; true;) {
Log.d(i + "", "Content");
if (i == 0) {
startup_logo.setBackgroundResource(R.anim.startup);
temp = (AnimationDrawable) startup_logo.getBackground();
fadeout.start();
}
else if (i == 1) {
featuredpanel.setBackgroundResource(R.anim.featured_move);
temp = (AnimationDrawable) featuredpanel.getBackground();
menu.setAnimation(fadein);
logo.setAnimation(fadein);
fadein.start();
}
else if (!temp.isRunning()) {
temp.start();
i++;
}
}
}
}
Another section of code defines startup_logo as follows:
startup_logo = (LinearLayout) findViewById (R.anim.startup);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/startup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@anim/startup" >
TRACEBACK:
09-08 01:02:31.239: E/AndroidRuntime(1105): FATAL EXCEPTION: main
09-08 01:02:31.239: E/AndroidRuntime(1105): java.lang.RuntimeException: Unable to start activity ComponentInfo{My.Taste.App/My.Taste.App.MyTasteActivity}: java.lang.NullPointerException
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.os.Looper.loop(Looper.java:137)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-08 01:02:31.239: E/AndroidRuntime(1105): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 01:02:31.239: E/AndroidRuntime(1105): at java.lang.reflect.Method.invoke(Method.java:511)
09-08 01:02:31.239: E/AndroidRuntime(1105): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-08 01:02:31.239: E/AndroidRuntime(1105): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-08 01:02:31.239: E/AndroidRuntime(1105): at dalvik.system.NativeStart.main(Native Method)
09-08 01:02:31.239: E/AndroidRuntime(1105): Caused by: java.lang.NullPointerException
09-08 01:02:31.239: E/AndroidRuntime(1105): at My.Taste.App.TBGStartAnimations.startup(TBGStartAnimations.java:18)
09-08 01:02:31.239: E/AndroidRuntime(1105): at My.Taste.App.MyTasteActivity.onCreate(MyTasteActivity.java:68)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.Activity.performCreate(Activity.java:4465)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-08 01:02:31.239: E/AndroidRuntime(1105): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-08 01:02:31.239: E/AndroidRuntime(1105): ... 11 more
I figured it out!
Shouldve searched by R.id not R.anim