Android 1.6: “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”

后端 未结 16 1169
滥情空心
滥情空心 2020-11-22 07:46

I\'m trying to open a dialog window, but every time I try to open it it throws this exception:

Uncaught handler: thread main exiting due to uncaught exceptio         


        
16条回答
  •  长发绾君心
    2020-11-22 08:03

    public class Splash extends Activity {
    
        Location location;
        LocationManager locationManager;
        LocationListener locationlistener;
        ImageView image_view;
        ublic static ProgressDialog progressdialog;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            progressdialog = new ProgressDialog(Splash.this);
               image_view.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
    
                            locationManager.requestLocationUpdates("gps", 100000, 1, locationlistener);
                            Toast.makeText(getApplicationContext(), "Getting Location plz wait...", Toast.LENGTH_SHORT).show();
    
                                progressdialog.setMessage("getting Location");
                                progressdialog.show();
                                Intent intent = new Intent(Splash.this,Show_LatLng.class);
    //                          }
            });
        }
    

    Text here:-
    use this for getting activity context for progressdialog

     progressdialog = new ProgressDialog(Splash.this);
    

    or progressdialog = new ProgressDialog(this);

    use this for getting application context for BroadcastListener not for progressdialog.

    progressdialog = new ProgressDialog(getApplicationContext());
    progressdialog = new ProgressDialog(getBaseContext());
    

提交回复
热议问题