good morning t tried to parse xml file online and show result in a simple listview i used asynch task to parse the xml file but i get this error
this the hole code :
public class Pdfreader extends Activity {
ArrayList<HashMap<String, String>> name=null;
ListView maListViewPdf;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/** Create a new layout to display the view */
setContentView(R.layout.pdf);
maListViewPdf = (ListView) findViewById(R.id.listpdf);
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
mProgressDialog = new ProgressDialog(Pdfreader.this);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setMessage("جاري التحميل....");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.show();
}
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
URL url = null;
try {
url = new URL("the url");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
org.w3c.dom.Document doc = null;
try {
doc = db.parse(new InputSource(url.openStream()));
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("item");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element fstElmnt = (Element) node;
NodeList nameList = ((org.w3c.dom.Document) fstElmnt).getElementsByTagName("title");
Element nameElement = (Element) nameList.item(0);
nameList = ((Node) nameElement).getChildNodes();
NodeList websiteList = ((org.w3c.dom.Document) fstElmnt).getElementsByTagName("link");
Element websiteElement = (Element) websiteList.item(0);
websiteList = ((Node) websiteElement).getChildNodes();
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", ((Node) nameList.item(0)).getNodeValue());
map.put("tel", ((Node) websiteList.item(0)).getNodeValue());
name.add(map);
System.out.println( ((Node) nameList.item(0)).getNodeValue());
}
return null;
}
protected void onPostExecute(Void result) {
SimpleAdapter adapt = new SimpleAdapter(Pdfreader.this,
name, R.layout.one_article,
new String[] { "title" },
new int[] { R.id.titreArticle });
// maListViewPdf.setAdapter(adapt);
/* WebView mWebView=new WebView(Pdfreader.this);
mWebView.loadUrl("http://ift.tt/1edRTVV");
setContentView(mWebView);*/
}
};
task.execute((Void[]) null);
}
}
this the log :
01-01 10:35:29.855: E/AndroidRuntime(1305): FATAL EXCEPTION: AsyncTask #1
01-01 10:35:29.855: E/AndroidRuntime(1305): java.lang.RuntimeException: An error occured while executing doInBackground()
01-01 10:35:29.855: E/AndroidRuntime(1305): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-01 10:35:29.855: E/AndroidRuntime(1305): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.lang.Thread.run(Thread.java:856)
01-01 10:35:29.855: E/AndroidRuntime(1305): Caused by: java.lang.ClassCastException: org.apache.harmony.xml.dom.ElementImpl cannot be cast to android.renderscript.Element
01-01 10:35:29.855: E/AndroidRuntime(1305): at com.example.albir.Pdfreader$1.doInBackground(Pdfreader.java:89)
01-01 10:35:29.855: E/AndroidRuntime(1305): at com.example.albir.Pdfreader$1.doInBackground(Pdfreader.java:1)
01-01 10:35:29.855: E/AndroidRuntime(1305): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-01 10:35:29.855: E/AndroidRuntime(1305): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
can you help me please
No comments:
Post a Comment