在我的应用程序中,我试图从URL获取xml文件。尝试get的url由一个字符串组成。以下是我的代码的一部分
URL url = new URL("http://..................");
Log.e("Gallery URl",""+url);
getWebPageContents(url);
}
private void getWebPageContents(URL url)
{
try{
if(url != null)
Log.e("webpage",""+url);
{
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet();
try
{
HttpResponse rsp = client.execute(get);
String tmpstr = EntityUtils.toString(rsp.getEntity());
Log.e("UserData "+tmpstr);
UserManual.IMGDATA=tmpstr;
getUserRegisteredContents(tmpstr);
}
catch(Exception asd)
{
Log.e(asd.toString());
}
}
当我在log cat中检查日志值时,它显示它正在进入URL然后进入getWebPageContents(url)
在getWebPageContents(URL url)中的它进入第一个try块而不是第二个try块
我出错的地方请帮助我......
答案 0 :(得分:1)
您没有在代码中使用该网址:
HttpGet get = new HttpGet();
我认为这就是你想要的:
URI uri = new URI("http://..................");
HttpGet get = new HttpGet(uri);
答案 1 :(得分:1)
您没有设置想要到达任何位置的网址,因此我认为rsp.getEntity()
会导致NullPointerException
另外HttpGet接受URI
或String
,因此您可以将其用作:
HttpGet get = new HttpGet("http://www.example.com");
或更改
URL url = new URL("http://..................");
到
URI url = new URI("http://..................");