1

一旦我的初始屏幕显示 1000 毫秒,我就会收到一条错误消息,指出“应用程序已意外停止。请重试。” 似乎应该在启动画面不工作后开始的活动。在启动画面之前,一切正常。Logcat 显示以下错误“ E/AndroidRuntime(5480): java.lang.RuntimeException: Unable to start activity 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);
}

}

4

1 回答 1

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;
    }
}
于 2012-04-25T18:30:44.093 回答