我陷入了一些奇怪的问题,我无法弄清楚我做错了什么。我有一个正在显示 UserInfo 的屏幕。为此,当我触发 web 服务并解析该数据并显示它时,我正在获取 XML,这在 2.3.3 中运行良好,但在 ICS 中无法解析。
这是我解析数据的方法::
XML ::
<?xml version="1.0"?>
<root>
<displayname>AAAA</displayname>
<gender>male</gender>
<city>AAAA</city>
<state>AAAA</state>
<country>AAA</country>
<image>http://www.example.com/documentSetting/test.jpg</image>
</root>
我的异步任务::
private class GetUserInfoTask extends AsyncTask<String, Integer, Document>
{
Document document = null;
GetUserInfoTask()
{
webAPIRequest = new WebAPIRequest();
}
@Override
protected Document doInBackground(String... urls)
{
document = webAPIRequest.performGet(urls[0]);
return document;
}
protected void onPostExecute(Document result)
{
try
{
if(result!=null)
{
Element node = (Element)result.getElementsByTagName("root").item(0);
if(node!=null)
{
websiteList = node.getElementsByTagName("root");
check = websiteList.getLength();
if(check!=0)
{
arrUserInfoList=null;
if(arrUserInfoList==null)
{
arrUserInfoList = new ArrayList<UserProfile>();
}
for(int j=0;j<websiteList.getLength();j++)
{
Element checkNode=(Element)websiteList.item(j);
UserProfile user=new UserProfile();
msg.display_name = getValueFromNode(checkNode,"displayname");
msg.gender = getValueFromNode(checkNode,"gender");
user.city = getValueFromNode(checkNode,"city");
user.state = getValueFromNode(checkNode,"state");
user.country = getValueFromNode(checkNode,"country");
user.image = getValueFromNode(checkNode,"image");
arrUserInfoList.add(user);
}
txt_user_name_top.setText(arrUserInfoList.get(0).displayname);
txt_user_gender.setText(arrUserInfoList.get(0).gender);
txt_user_status.setText(arrUserInfoList.get(0).status);
txt_user_country.setText(arrUserInfoList.get(0).country);
txt_user_country.setText(arrUserInfoList.get(0).city);
}
}
new LoadingFriendImagesTask().execute();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
我的 PerformGet 方法::
public Document performGet(String url)
{
Log.d("webAPIRequest url = ", url);
Document doc = null;
try
{
DefaultHttpClient client = new DefaultHttpClient();
URI uri = new URI(url);
HttpGet method = new HttpGet(uri);
HttpResponse res = client.execute(method);
InputStream data = res.getEntity().getContent();
String s = convertStreamToString(data);
ByteArrayInputStream str=new ByteArrayInputStream(s.getBytes());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(str);
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e)
{
e.printStackTrace();
}
return doc;
}
您的宝贵建议和帮助将不胜感激......在此先感谢...... :)