我有点困惑......在动画之后,启动画面应该启动一个intent函数来操作下一个.java活动文件...但是当它在模拟器中的启动画面后运行时,它不会工作。我打开了Logcat,它说了一些java.lang.nullpointer和运行在Pause功能的运行时异常...有人能解释一下这个吗?感谢。
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(ZygoteInit.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!
答案 0 :(得分:1)
卫生署!
private void startAnimating()
{
Animation pearfadeact = AnimationUtils.loadAnimation(this, R.anim.fadein);
ImageView pearfade = (ImageView) findViewById(R.id.pearish);
...
}
删除我突出显示的Imageview。问题是,当您已经拥有一个同名的成员时,您正在创建一个局部变量
答案 1 :(得分:1)
你有一个NullPointerException。这可能是因为在startAnimating方法中,您有以下代码:
ImageView pearfade = (ImageView) findViewById(R.id.pearish)
该变量声明隐藏了您的类成员变量定义。你需要纠正这个问题。 :)
答案 2 :(得分:0)
我认为你的问题在线perfade.clearAnimation(),暂停将其删除
编辑:其他方式是如上所述设置声明oncreate ImageView perfade;
而不是在startanimating方法中使用它:
pearfade = (ImageView) findViewById(R.id.pearish);
答案 3 :(得分:0)
我的猜测是onPause pearfade.clearAnimation();
为空,基于
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
在您的日志中