作者TllDA (踢打)
看板java
标题[问题] Android Widget要连HTTP有问题
时间Tue Oct 19 22:38:38 2010
大家好
我在练习写可以上网抓一些资料的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
1F:→ meconin:先分成 HttpResponse resp;resp = client.execute(req);吧 10/19 23:10
2F:推 a1234957:exception是什麽... 10/20 06:59
3F:→ TllDA:exception就是如果包在try...catch里 会跑到catch那段 10/20 08:50
4F:推 LPH66:...我怎麽觉得二楼在问出了什麽 exception XD 10/20 09:24
5F:→ a1234957:catch然後勒 不处理一下? 10/20 10:56