[問題] Android Widget要連HTTP有問題

看板java作者 (踢打)時間13年前 (2010/10/19 22:38), 編輯推噓2(203)
留言5則, 4人參與, 最新討論串1/2 (看更多)
大家好 我在練習寫可以上網抓一些資料的widget 可是HttpResponse的宣告每次執行時都會出錯(Eclipse檢查時是正常) 我的大概結構如下 public void onUpdate (Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { updateAppWidget(context, appWidgetManager, appWidgetIds); } public void updateAppWidget (Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) { String weather = ""; RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main); views.setTextViewText(R.id.tvPlace, "TIIDA test"); String url = "http://www.google.com/ig/api?&weather=taipei"; HttpClient client = new DefaultHttpClient(); HttpGet req = new HttpGet(url); HttpResponse resp = client.execute(req); //this line will go to exception. } 其他部分先省略 我是想從google抓天氣資訊 但每次都最後這個HttpResponse的宣告處就會跑到Exception 不知道要怎麼解 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.42.10.236

10/19 23:10, , 1F
先分成 HttpResponse resp;resp = client.execute(req);吧
10/19 23:10, 1F

10/20 06:59, , 2F
exception是什麼...
10/20 06:59, 2F

10/20 08:50, , 3F
exception就是如果包在try...catch裡 會跑到catch那段
10/20 08:50, 3F

10/20 09:24, , 4F
...我怎麼覺得二樓在問出了什麼 exception XD
10/20 09:24, 4F

10/20 10:56, , 5F
catch然後勒 不處理一下?
10/20 10:56, 5F
文章代碼(AID): #1ClQrmhg (java)
文章代碼(AID): #1ClQrmhg (java)