我正在使用 XmlPullParserFactory 解析在线 Xml 并在列表视图中显示详细信息。我已经设置了检查互联网的条件,但有时获取数据和崩溃需要时间。我正在使用的代码如下。
private void runningABackProcess() {
Handler mHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = new Runnable() {
public void run() {
try{
//Thread.sleep(5000);
new DoSomeTask().execute();
}catch(Exception e){}
// myPd_ring.dismiss();
}
};
mHandler.post(myRunnable);
}
private class DoSomeTask extends AsyncTask<Void, Void, Void>
{
@Override
protected Void doInBackground(Void... arg0) {
try {
isInternetPresent = icd.isConnectingToInternet
if(isInternetPresent){
URL url = new URL("njhgjghjkjhkjl");
XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
XmlPullParser xpp=factory.newPullParser();
xpp.setInput(getInputStream(url), "UTF_8");
int eventType=xpp.getEventType();
if(eventType!=XmlPullParser.END_DOCUMENT)
{
if(eventType==XmlPullParser.START_DOCUMENT)
{
while(eventType!=XmlPullParser.END_DOCUMENT )
{
xpp_name=xpp.getName();
if((xpp_name!=null) )
{
--------------------
-------------------------
}
}
}
}
和
public InputStream getInputStream(URL url) {
try {
InputStream str=null;
isInternetPresent=icd.isConnectingToInternet();
if(isInternetPresent)
{
str=url.openConnection().getInputStream();
if(str!= null)
{
return str;
}else{
new AlertDialogBox(getActivity()).show(getFragmentManager(),"MyDialog");
}
}else{
new AlertDialogBox(getActivity()).show(getFragmentManager(), "MyDialog");
}
return str;
//}
} catch (IOException e) {
return null;
}
}
以下是我得到的错误: