我发布了一个免费的应用程序图像滑块,其中包含针对小孩子的口语。几周前,我收到了第一份崩溃报告。这似乎很少发生(每周一次)。
报告指出:Splash.onCreate() 中的 NullPointerException
Stack tace 显示此消息:
java.lang.RuntimeException: Unable to start activity
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at co.uk.musenuovo.michal.Splash.onCreate(Splash.java:18)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
我在 spash 活动中的代码(初始屏幕显示图像并播放 5 秒):
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle ShowSplashPage) {
// TODO Auto-generated method stub
super.onCreate(ShowSplashPage);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.xylophone_open);
ourSong.start();
Thread timer = new Thread() {
public void run() {
try{
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPoint = new Intent("co.uk.musenuovo.michal.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
该错误清楚地指出了spash活动中的onstart。这是因为我忘了导入一些库吗?还是我忘了分配什么?我对java很陌生,不知道如何调试并找出问题所在。我读了很多,NullPointerException
但这似乎是一个模糊的错误。谢谢你的帮助。