作者epicwonder (金州土匪队)
看板java
标题Re: [问题] Android Widget要连HTTP有问题
时间Wed Oct 20 23:25:39 2010
※ 引述《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
1F:推 ckf:推..新手蛮容易忘记这一点!! 10/23 00:47
2F:推 TllDA:我发现问题在我的emulator不能上网... 10/23 23:55
3F:推 QQting:模拟器很烂 时常不能上网 或是用到一半网路就挂了 10/24 11:31
4F:推 QQting:遇到这个情况 我都关掉模拟器再重开~"~ 10/24 16:34