runtime - Alertdialog does not work, it make exception in Android -


I try to execute the following code but it is causing problems without code works fine without a dialog box Pop up and want to ask the user to enable its locked WiFi. Override Protected Zero OnCreate (bundled savedInstanceState) {// TODO auto-created method stub super.onCreate (savedInstanceState); SetContentView (R.layout.welcome); Thread Timer = New Thread () {Public Running Zero () {try {sleep (2000); } Grip (Interrupted e) e.printStackTrace (); } Finally {showAlert (); }}}; Timer.start (); }} Public Zero Show Alert () {AlertDialog.Builder Warning DialogBuilder = New AlertDialog.Builder (this); // Set Headline DialogBuilder.setTitle ("Your Title"); // Set dialog message alertDialogBuilder .setMessage ("yes click to exit!") .setCancelable (wrong) .setPositiveButton ("Yes", New DialogInterface.OnClickListener {Public Zero onClick (DialogInterface Dialog, Integer ID) { // If this button is clicked, close to / current activity, Welcome.this.finish ();}}) .setNegativeButton ("No", New DialogInterface.OnClickListener () {Public Zero onClick (DialogInterface Dialog, Integer ID ) {// If this button is clicked, simply close the dialog box and do nothing; dialog.cancel ();}}); // Alert Dialog Warning Dialog = Alert DLObuilder Create (); // show it alert dialogue.show (); }

The progressive code throws the same error within the log history and comment lines here!

  11: 46: 57.306: E / AndroidRuntime (2140): Fatal exception: Thread-141 11: 46: 57.306: E / Android Random (2140): java.lang.RuntimeException: The header can not be made inside the thread which is not called Looper.prepare () 11 : 46: 57.306: E / AndroidRuntime (2140): on android.os.Handler & lt; Init & gt; (Handler.java:197) 11:. 46: 57.306: E / AndroidRuntime (2140):. On &roid.os.Handler & lt; Init & gt; (Handler.java:111) 11: 46: 57.306: E / AndroidRuntime (2140): android.app.Dialog at & lt; Init & gt; (Dialog.java:107) 11:. 46: 57.306: E / AndroidRuntime (2140): make android.app.AlertDialog & lt; Init & gt; (AlertDialog.java:114) 11:. 46: 57.306: E / AndroidRuntime (2140): $ Builder.create (AlertDialog.java:931) at android.app.AlertDialog 11: 46: 57.306: E / Android Random (2140): at com.example.core4voipmobiledialer. welcome. ShowRelert (Welcome 116) 11: 46: 57.306: E / Android Random (2140): Aler.Welcome $ 1.run at com.example.core4voipmobiledi (welcome.java35)    

Use to show RunOnUiThread toast or alert dialog for.

  runOnUiThread {NewOnRunball} {@Override Public Zero Run () {ShowAlert (); }});   

You are calling it from a worker thread to toast you from within the main thread Make text () or call the alert dialog. You can also use a handler.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -