2012-04-13 10 views
0

enter code here Ich versuche, einen Fortschritt Dialog in meiner Android-Anwendung zu setzen, und ich habe ein wenig Probleme damit. Ich bin neu in Android und folge diesem Tutorial: Android Activity Force Schließen Problem

Wenn ich meine App auf meinem Handy teste alles ist es Force Closes. Kann jemand bitte helfen? Heres meine .Java Aktivität:

public class XXXXXActivity extends Activity { 
private ProgressDialog progressDialog; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    WebView myWebView=(WebView)findViewById(R.id.webview); 
    myWebView.addJavascriptInterface(new JavaScriptInterface(this),"Android"); 
    WebSettings websettings = 
      myWebView.getSettings(); 
    websettings.setJavaScriptEnabled(true); 
    myWebView.setWebViewClient(new MyWebViewClient()); 
    myWebView.loadUrl("http://XXXXX.com"); 
} 

private void runDialog(final int seconds) 
{ 
    progressDialog = ProgressDialog.show(this, "Please wait...", "Loading..."); 
    new Thread(new Runnable(){ 
     public void run(){ 
      try { 
         Thread.sleep(seconds * 1000); 
       progressDialog.dismiss(); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
    }).start(); 
} 
public class JavaScriptInterface { 
    Context mContext; 
    /** Instantiate the interface and set the context*/ 
    JavaScriptInterface(Context c) { 
     mContext = c; 
    } 
    /** Show a toast from the web page*/ 
    public void showToast(String toast) { 
     Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); 
    } 
} 
private class MyWebViewClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading (WebView view, String url) { 
     view.loadUrl(url); 
     if 
     (Uri.parse(url).getHost().equals("XXXXX.com")) { 
      // This is my web site, so do not override; let my WebView load the page 
      return false; 
     } 
     // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs 
     Intent intent=new 
       Intent (Intent.ACTION_VIEW,Uri.parse(url)); 
     startActivity(intent); 
     return true; 
    } 
} 

Logcat:

[2012-04-13 19:44:55 - XXXXX] ------------------------------ 
[2012-04-13 19:44:55 - XXXXX] Android Launch! 
[2012-04-13 19:44:55 - XXXXX] adb is running normally. 
[2012-04-13 19:44:55 - XXXXX] No Launcher activity found! 
[2012-04-13 19:44:55 - XXXXX] The launch will only sync the application package on the device! 
[2012-04-13 19:44:55 - XXXXX] Performing sync 
[2012-04-13 19:44:55 - XXXXX] Automatic Target Mode: Preferred AVD 'MY-PHONE' is not available. Launching new emulator. 
[2012-04-13 19:44:55 - XXXXX] Launching a new emulator with Virtual Device 'MY-PHONE' 
[2012-04-13 19:45:08 - Emulator] emulator: WARNING: Unable to create sensors port: Unknown error 
[2012-04-13 19:45:08 - XXXXX] New emulator found: emulator-5554 
[2012-04-13 19:45:08 - XXXXX] Waiting for HOME ('android.process.acore') to be launched... 
[2012-04-13 19:46:05 - XXXXX] emulator-5554 disconnected! Cancelling 'sync'! 
+0

posten Sie bitte Ihre Logcat-Ausgabe. –

Antwort

0

Ich sehe ein Problem: Sie Dialog in Nicht-GUI-Thread entlassen:

new Thread(new Runnable(){ 
     public void run(){ 
      try { 
         Thread.sleep(seconds * 1000); 
       progressDialog.dismiss(); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
    }).start(); 

Dieser Code ist sehr seltsam Ich denke, du solltest die Logik überhaupt neu schreiben.

+0

Dies sollte nicht das Problem sein, weil er runDialog Funktion nirgendwo im Code aufrufen. – San

+0

@AlexKlimashevsky Ist es möglich für Sie, einen Link oder etwas zu finden, um den Code als neu zu schreiben? Wie ich in meiner Frage gesagt habe, bin ich neu in Android. – SMOKE

+0

@SaneeshCS Muss ich die runDialog-Funktion im Code aufrufen? Wie ich in meiner Frage gesagt habe, bin ich neu in Android. Auch das ist alles, was mir das Tutorium gesagt hat. Ich frage mich, ob der Typ etwas ausgelassen hat. – SMOKE