2017-06-22 52 views
-4

它在"startActivity(i);"中顯示錯誤。startActivity(i);顯示錯誤

Error: startActivity (android.content.Intent) in Activity cannot be applied.

這裏是代碼:

public class LoadingScreen extends AppCompatActivity { 

    private static int SplashInterval = 2000; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.loading_screen); 

     new Handler().postDelayed(new Runnable(){ 
      @Override 
      public void run(){ 
       //TODO Auto-generated method stub 
       Intent i = new Intent(LoadingScreen.this, MainActivity.class); 
       startActivity(i); 

       this.finish(); 
      } 
      private void finish(){ 
       //TODO Auto-generated method stub 
      } 
     },SplashInterval); 
    }; 
} 
+0

我想你忘了問這個問題:p – Nathan

+0

paste LoadingScreen.this.finish();而不是this.finish(); –

回答

0

試試這個,

public class LoadingScreen extends Activity { 

    private static int SplashInterval = 2000; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.loading_screen); 

     new Handler().postDelayed(new Runnable(){ 
      @Override 
      public void run(){ 
       //TODO Auto-generated method stub 
       Intent i = new Intent(LoadingScreen.this, MainActivity.class); 
       startActivity(i); 
       finish(); 
      } 

     },SplashInterval); 
    }; 
} 
0

試試這個

new Handler().postDelayed(new Runnable() { 

     /* 
     * Showing splash screen with a timer. This will be useful when you 
     * want to show case your app logo/company 
     */ 

     @Override 
     public void run() { 
      Intent i = new Intent(LoadingScreen.this, MainActivity.class); 
      startActivity(i); 
      finish(); 

      // close this activity 
     } 
    }, SplashInterval); 
0

刪除此行

this.finish(); 

寫的是內部處理

而做LoadingScreen.this.finish(); 實現這個活動的結束;