2012-04-25 62 views
1

一旦我的啓動畫面顯示1000ms,我收到一個錯誤,指出「應用程序意外停止,請重試。」這似乎是一個活動,應該在啓動屏幕不工作後開始。在啓動畫面之前,一切正常。 Logcat 顯示以下錯誤「E/AndroidRuntime(5480):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.xxxxx.home/com.xxxxx.home.xxxxx}:java.lang.NullPointerException。I beleive the問題是我的飛濺類,但不能針點在哪裏。任何有識之士將不勝感激。啓動畫面後的活動

公共類飛濺延伸活動{

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); 
} 

}

+2

你有沒有註冊你的所有活動類在顯示文件? – MAC 2012-04-25 18:28:42

+0

是的......我的飛濺活動在清單中註冊並設置爲MAIN和LAUNCHER。我的第二個活動更改爲默認,名稱設置爲與「意圖」中的名稱相同 – user1165694 2012-04-25 18:39:07

回答

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; 
    } 
} 
+0

哇這是史詩。偉大的代碼。工作過一種享受。謝謝@Aerrow – BENN1TH 2016-11-05 21:49:42

+0

我猜SlideMainActivity是一個動畫滑入視圖? – BENN1TH 2016-11-05 21:51:49

+0

對不起,我在這個時候到來,但沒有人知道如何運行一個應用程序後,在Java桌面應用程序的splashscreen? – 2017-07-14 09:18:59