2012-04-05 3 views
2

アクティビティはポジティブボタン付きのダイアログウィンドウを表示します。ボタンをクリックすると、アクティビティStaticdisplayに移動します。私は活動を読み込んでいるときに進行状況バーを追加しようとしています。次のエラーが表示されます。 $BadTokenException: Unable to add window -- token null is not for an application エラーウィンドウを追加できません - トークンnullはアプリケーション用ではありません

これはプロセスバーを追加するコードです。progressBar.show();この行にエラーが表示されます。このエラーからどうやって抜け出すことができますか?ありがとう。 getApplicationContextの代わりに

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setCustomTitle(title); 

     builder.setMessage(R.string.app_description).setPositiveButton(
       "Ok", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         if (Registration.isRunning == false) { 
          startService(new Intent(
            getApplicationContext(), 
            Registration.class)); 
         } 
         staticInfo(); 
         if (Registration.ruid == null) 
          Registration.ruid = uId; 
         progressBar = new ProgressDialog(
           getApplicationContext()); 
         progressBar.setCancelable(true); 
         progressBar.setMessage("Loading Activity..."); 
         progressBar 
           .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
         progressBar.setProgress(0); 
         progressBar.setMax(100); 
         progressBar.show(); 
         progressBarStatus = 0; 

         new Thread(new Runnable() { 
          public void run() { 
           while (progressBarStatus < 100) { 

            progressBarStatus = 100; 

            progressBarHandler.post(new Runnable() { 
             public void run() { 
              progressBar 
                .setProgress(progressBarStatus); 
             } 
            }); 
           } 

           if (progressBarStatus >= 100) { 

            progressBar.dismiss(); 
            startActivity(new Intent(
              getApplicationContext(), 
              StatisticDisplay.class)); 
           } 
          } 
         }).start(); 

        } 

       }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 
    } else { 
     startActivity(new Intent(getApplicationContext(), 
       StatisticDisplay.class)); 
    } 
} 

答えて

15
progressBar = new ProgressDialog(getApplicationContext()); 

()ウルActivityName.thisかのgetContext()も

+0

私を助けを渡す.. +1 –

関連する問題