一旦我的启动画面显示1000毫秒,我收到错误消息“应用程序已意外停止。请重试。”这似乎是一个活动,应该在启动画面不起作用后启动。在启动画面之前,一切正常。 logcat的 显示以下错误“E / AndroidRuntime(5480):java.lang.RuntimeException:无法启动活动ComponentInfo {com.xxxxx.home / com.xxxxx.home.xxxxx}:java.lang.NullPointerException。我相信问题是我的Splash Class但不能指出哪里。任何见解都会非常感激。
公共类Splash扩展了Activity {
private final int SPLASH_DISPLAY_LENGTH = 1000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent openxxxxx = new Intent("com.xxxxx.home.XXXXX");
startActivity(openxxxxx);
}
}, SPLASH_DISPLAY_LENGTH);
}
}
答案 0 :(得分:3)
以下是您可以使用的完整代码,
package com.fsp.slideview;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
public class ImageSplashActivity extends Activity {
/**
* The thread to process splash screen events
*/
private Thread mSplashThread;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
final ImageSplashActivity sPlashScreen = this;
mSplashThread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
wait(2000);
}
} catch (InterruptedException ex) {
}
finish();
Intent intent = new Intent();
intent.setClass(sPlashScreen, SlideMainActivity.class);
startActivity(intent);
}
};
mSplashThread.start();
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
if (evt.getAction() == MotionEvent.ACTION_DOWN) {
synchronized (mSplashThread) {
mSplashThread.notifyAll();
}
}
return true;
}
}