I'm a little confused... After the animation, the splash screen is supposed to start an intent function to operate the next .java activity file... but when it runs after the splash screen in the emulator, it wont work. I opened Logcat and it said something to an extent of a java.lang.nullpointer and runtime exception running at the Pause feature... can anyone explain this to me? Thanks.
package com.unicorn.test.whee;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class SplashScreenPear extends Activity {
ImageView pearfade;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pear); }
private void startAnimating(){
Animation pearfadeact = AnimationUtils.loadAnimation(this, R.anim.fadein);
ImageView pearfade = (ImageView) findViewById(R.id.pearish);
pearfadeact.setAnimationListener(new AnimationListener(){
public void onAnimationEnd(Animation animation) {
// The animation has ended, transition to the Main Menu screen
startActivity(new Intent(SplashScreenPear.this, Unicorn.class));
SplashScreenPear.this.finish(); }
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
pearfade.startAnimation(pearfadeact);
}
@Override
protected void onPause() {
super.onPause();
pearfade.clearAnimation();
}
@Override
protected void onResume() {
super.onResume();
startAnimating();
}
}
Logcat:
01-24 23:54:22.040: INFO/ActivityManager(74): Displayed com.unicorn.test.whee/.SplashScreenPear: +2s317ms (total +2m20s769ms)
01-24 23:54:25.790: INFO/ActivityManager(74): Starting: Intent { cmp=com.unicorn.test.whee/.Unicorn } from pid 579
01-24 23:54:25.790: DEBUG/AndroidRuntime(579): Shutting down VM
01-24 23:54:25.790: WARN/dalvikvm(579): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): FATAL EXCEPTION: main
01-24 23:54:25.790: ERROR/AndroidRuntime(579): java.lang.RuntimeException: Unable to pause activity {com.unicorn.test.whee/com.unicorn.test.whee.SplashScreenPear}: java.lang.NullPointerException
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2329)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2286)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2266)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread.access$1700(ActivityThread.java:117)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.os.Looper.loop(Looper.java:123)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(Zygot开发者_如何学PythoneInit.java:839)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at dalvik.system.NativeStart.main(Native Method)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): Caused by: java.lang.NullPointerException
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at com.unicorn.test.whee.SplashScreenPear.onPause(SplashScreenPear.java:50)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.Activity.performPause(Activity.java:3853)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1190)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2316)
01-24 23:54:25.790: ERROR/AndroidRuntime(579): ... 12 more
01-24 23:54:26.339: WARN/ActivityManager(74): Activity pause timeout for HistoryRecord{4067cb18 com.unicorn.test.whee/.SplashScreenPear}
01-24 23:54:28.169: INFO/Process(579): Sending signal. PID: 579 SIG: 9
01-24 23:54:28.210: INFO/ActivityManager(74): Process com.unicorn.test.whee (pid 579) has died.
01-24 23:54:28.230: ERROR/InputDispatcher(74): channel '405fa740 com.unicorn.test.whee/com.unicorn.test.whee.SplashScreenPear (server)' ~ Consumer closed input channel or an error occurred. events=0x8
01-24 23:54:28.230: ERROR/InputDispatcher(74): channel '405fa740 com.unicorn.test.whee/com.unicorn.test.whee.SplashScreenPear (server)' ~ Channel is unrecoverably broken and will be disposed!
Well you have a NullPointerException. This is probably because in your startAnimating method you have the following code:
ImageView pearfade = (ImageView) findViewById(R.id.pearish)
That variable declaration hides your class member variable definition. You need to correct that. :)
Doh!
private void startAnimating()
{
Animation pearfadeact = AnimationUtils.loadAnimation(this, R.anim.fadein);
ImageView pearfade = (ImageView) findViewById(R.id.pearish);
...
}
Remove this Imageview that i've highlighted. The problem was that you are creating a local variable when you already had a member by the same name
I think your problem is on line perfade.clearAnimation()
, remove it from onpause.
Edited
The other way is set declaration as above oncreate ImageView perfade;
and then do use this in startanimating method:
pearfade = (ImageView) findViewById(R.id.pearish);
My guess would be that in onPause pearfade.clearAnimation();
is null, based on
01-24 23:54:25.790: ERROR/AndroidRuntime(579): Caused by: java.lang.NullPointerException
01-24 23:54:25.790: ERROR/AndroidRuntime(579): at com.unicorn.test.whee.SplashScreenPear.onPause(SplashScreenPear.java:5
in your log
精彩评论