2012-10-06 101 views
0
 catch (UnknownHostException e) { 
      e.printStackTrace(); 
      progressDialog.dismiss(); 
      AlertDialog connection = new AlertDialog.Builder(
        NewsScreenActivity.this) 
        .setTitle("No Network Found") 
        .setMessage(
          "Internet Connection Reqired To Use this Application,please try again latter") 
        .setPositiveButton("Ok", 
          new DialogInterface.OnClickListener() { 

           public void onClick(DialogInterface dialog, 
             int whichButton) { 

          //  progressDialog.dismiss(); 
           } 
          }).create(); 

      connection.show(); 


      Log.i("=================== UnknownHostException", "======"); 
     } 

錯誤:的java.net.UnknownHostException:

10-06 17:35:02.488: W/System.err(20393): java.net.UnknownHostException: maritimeglobalnews.com 
10-06 17:35:02.488: W/System.err(20393): at java.net.InetAddress.lookupHostByName(InetAddress.java:506) 
10-06 17:35:02.488: W/System.err(20393): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294) 
10-06 17:35:02.488: W/System.err(20393): at java.net.InetAddress.getAllByName(InetAddress.java:256) 
10-06 17:35:02.488: W/System.err(20393): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136) 
10-06 17:35:02.488: W/System.err(20393): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 
10-06 17:35:02.488: W/System.err(20393): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 
10-06 17:35:02.498: W/System.err(20393): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 
10-06 17:35:02.498: W/System.err(20393): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 
10-06 17:35:02.498: W/System.err(20393): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 
10-06 17:35:02.498: W/System.err(20393): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 
10-06 17:35:02.498: W/System.err(20393): at com.MariTimeGlobalNews.NewsScreenActivity.getData(NewsScreenActivity.java:248) 
10-06 17:35:02.498: W/System.err(20393): at com.MariTimeGlobalNews.NewsScreenActivity$AllDataAsyn.doInBackground(NewsScreenActivity.java:138) 
10-06 17:35:02.508: W/System.err(20393): at com.MariTimeGlobalNews.NewsScreenActivity$AllDataAsyn.doInBackground(NewsScreenActivity.java:1) 
10-06 17:35:02.508: W/System.err(20393): at android.os.AsyncTask$2.call(AsyncTask.java:185) 
10-06 17:35:02.508: W/System.err(20393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
10-06 17:35:02.508: W/System.err(20393): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
10-06 17:35:02.508: W/System.err(20393): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
10-06 17:35:02.508: W/System.err(20393): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
10-06 17:35:02.508: W/System.err(20393): at java.lang.Thread.run(Thread.java:1019) 
10-06 17:35:02.538: W/dalvikvm(20393): threadid=9: thread exiting with uncaught exception (group=0x40018560) 
10-06 17:35:02.548: E/AndroidRuntime(20393): FATAL EXCEPTION: AsyncTask #1 
10-06 17:35:02.548: E/AndroidRuntime(20393): java.lang.RuntimeException: An error occured while executing doInBackground() 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.os.AsyncTask$3.done(AsyncTask.java:200) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.lang.Thread.run(Thread.java:1019) 
10-06 17:35:02.548: E/AndroidRuntime(20393): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.os.Handler.<init>(Handler.java:121) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.app.Dialog.<init>(Dialog.java:101) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.app.AlertDialog.<init>(AlertDialog.java:63) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.app.AlertDialog.<init>(AlertDialog.java:59) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.app.AlertDialog$Builder.create(AlertDialog.java:786) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at com.MariTimeGlobalNews.NewsScreenActivity.getData(NewsScreenActivity.java:450) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at com.MariTimeGlobalNews.NewsScreenActivity$AllDataAsyn.doInBackground(NewsScreenActivity.java:138) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at com.MariTimeGlobalNews.NewsScreenActivity$AllDataAsyn.doInBackground(NewsScreenActivity.java:1) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at android.os.AsyncTask$2.call(AsyncTask.java:185) 
10-06 17:35:02.548: E/AndroidRuntime(20393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
10-06 17:35:02.548: E/AndroidRuntime(20393): ... 4 more 

回答

1

試試這個。

runOnUiThread(new Runnable() 
{ 
    public void run() 
    { 
      // Your Alert Code 
    } 
}); 
0

使用的onCreate methhod下面的代碼:

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 
+0

感謝您的重播 – Android

相關問題