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

看板java作者 (金州土匪隊)時間15年前 (2010/10/20 23:25), 編輯推噓4(400)
留言4則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《TllDA (踢打)》之銘言: : 大家好 : 我在練習寫可以上網抓一些資料的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); 用一下try catch看是什麼錯誤 請用adb logcat看debug logcat 會不會是你的xml沒有宣路 使用網路的權限?? try{ HttpResponse resp = client.execute(req); //this line will go to exception. }catch(Exception e){ Log.d("Debug", "Exception e:"+e); } : } : 其他部分先省略 : 我是想從google抓天氣資訊 : 但每次都最後這個HttpResponse的宣告處就會跑到Exception : 不知道要怎麼解 : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.137.25.26

10/23 00:47, , 1F
推..新手蠻容易忘記這一點!!
10/23 00:47, 1F

10/23 23:55, , 2F
我發現問題在我的emulator不能上網...
10/23 23:55, 2F

10/24 11:31, , 3F
模擬器很爛 時常不能上網 或是用到一半網路就掛了
10/24 11:31, 3F

10/24 16:34, , 4F
遇到這個情況 我都關掉模擬器再重開~"~
10/24 16:34, 4F
文章代碼(AID): #1ClmdrXa (java)
文章代碼(AID): #1ClmdrXa (java)