android - Apps can't read my XML webservice -
i got xml in www.ravaana.ml/webservice/1.xml , got xml here http://www.ravaana.ml/webservice/2.xml apps cant read it. dont know should do.
here's code :
public class beritaterbaru extends fragment {
// variables xmlparser parser; document doc; string xml; listview lv; listviewadapter adapter; arraylist<hashmap<string, string>> menuitems; progressdialog pdialog; // xml node keys static final string key_item = "item"; // parent node static final string key_id = "id"; static final string key_judul = "judul"; static final string key_berita = "berita"; // flag current page int current_page = 0; public void onstart() { super.onstart(); lv = (listview) getview().findviewbyid(r.id.list); menuitems = new arraylist<hashmap<string, string>>(); new loadmorelistview().execute(); // loadmore button button btnloadmore = new button(getactivity()); btnloadmore.settext("load more"); // adding load more button lisview @ bottom lv.addfooterview(btnloadmore); // getting adapter adapter = new listviewadapter(getactivity(), menuitems); lv.setadapter(adapter); /** * listening load more button click event * */ btnloadmore.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // starting new async task new loadmorelistview().execute(); } }); /** * listening listview single row selected * **/ lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem string name = ((textview) view.findviewbyid(r.id.name)) .gettext().tostring(); // starting new intent intent in = new intent(getactivity(), singlemenuitemactivity.class); in.putextra(key_judul, name); startactivity(in); } }); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_beritaterbaru, container, false); return view; } /** * async task send request url gets new list view data appends * list view * */ private class loadmorelistview extends asynctask<void, void, void> { @override protected void onpreexecute() { // showing progress dialog before sending http request pdialog = new progressdialog(getactivity()); pdialog.setmessage("please wait.."); pdialog.setindeterminate(true); pdialog.setcancelable(false); pdialog.show(); } protected void doinbackground(void... unused) { // increment current page current_page += 1; // next page request string url = "http://www.ravaana.ml/webservice/" + current_page + ".xml"; parser = new xmlparser(); xml = parser.getxmlfromurl(url); // getting xml doc = parser.getdomelement(xml); // getting dom element nodelist nl = doc.getelementsbytagname(key_item); // looping through item nodes <item> (int = 0; < nl.getlength(); i++) { // creating new hashmap hashmap<string, string> map = new hashmap<string, string>(); element e = (element) nl.item(i); // adding each child node hashmap key => value map.put(key_id, parser.getvalue(e, key_id)); map.put(key_judul, parser.getvalue(e, key_judul)); map.put(key_berita, parser.getvalue(e, key_berita)); // adding hashlist arraylist menuitems.add(map); } return null; } protected void onpostexecute(void unused) { // closing progress dialog pdialog.dismiss(); // listview current position - used maintain scroll position int currentposition = lv.getfirstvisibleposition(); // appending new data menuitems arraylist adapter = new listviewadapter(getactivity(), menuitems); lv.setadapter(adapter); // setting new scroll position lv.setselectionfromtop(currentposition + 0, 0); } }
}
and here logcat
06-26 00:57:30.050: d/dalvikvm(808): gc_for_alloc freed 206k, 6% free 5068k/5372k, paused 32ms, total 32ms 06-26 00:57:30.060: e/error:(808): unexpected token (position:text @1:4 in java.io.stringreader@b4fbbbf0) 06-26 00:57:30.060: w/dalvikvm(808): threadid=11: thread exiting uncaught exception (group=0xb4aa7b90) 06-26 00:57:30.060: e/androidruntime(808): fatal exception: asynctask #1 06-26 00:57:30.060: e/androidruntime(808): process: info.androidhive.slidingmenu, pid: 808 06-26 00:57:30.060: e/androidruntime(808): java.lang.runtimeexception: error occured while executing doinbackground() 06-26 00:57:30.060: e/androidruntime(808): @ android.os.asynctask$3.done(asynctask.java:300) 06-26 00:57:30.060: e/androidruntime(808): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) 06-26 00:57:30.060: e/androidruntime(808): @ java.util.concurrent.futuretask.setexception(futuretask.java:222) 06-26 00:57:30.060: e/androidruntime(808): @ java.util.concurrent.futuretask.run(futuretask.java:242) 06-26 00:57:30.060: e/androidruntime(808): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) 06-26 00:57:30.060: e/androidruntime(808): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 06-26 00:57:30.060: e/androidruntime(808): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 06-26 00:57:30.060: e/androidruntime(808): @ java.lang.thread.run(thread.java:841) 06-26 00:57:30.060: e/androidruntime(808): caused by: java.lang.nullpointerexception 06-26 00:57:30.060: e/androidruntime(808): @ info.androidhive.slidingmenu.beritaterbaru$loadmorelistview.doinbackground(beritaterbaru.java:129) 06-26 00:57:30.060: e/androidruntime(808): @ info.androidhive.slidingmenu.beritaterbaru$loadmorelistview.doinbackground(beritaterbaru.java:1) 06-26 00:57:30.060: e/androidruntime(808): @ android.os.asynctask$2.call(asynctask.java:288) 06-26 00:57:30.060: e/androidruntime(808): @ java.util.concurrent.futuretask.run(futuretask.java:237) 06-26 00:57:30.060: e/androidruntime(808): ... 4 more 06-26 00:57:32.400: e/windowmanager(808): android.view.windowleaked: activity info.androidhive.slidingmenu.mainactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{b4f5d9e0 v.e..... r......d 0,0-383,96} added here 06-26 00:57:32.400: e/windowmanager(808): @ android.view.viewrootimpl.<init>(viewrootimpl.java:346) 06-26 00:57:32.400: e/windowmanager(808): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:248) 06-26 00:57:32.400: e/windowmanager(808): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.dialog.show(dialog.java:286) 06-26 00:57:32.400: e/windowmanager(808): @ info.androidhive.slidingmenu.beritaterbaru$loadmorelistview.onpreexecute(beritaterbaru.java:116) 06-26 00:57:32.400: e/windowmanager(808): @ android.os.asynctask.executeonexecutor(asynctask.java:587) 06-26 00:57:32.400: e/windowmanager(808): @ android.os.asynctask.execute(asynctask.java:535) 06-26 00:57:32.400: e/windowmanager(808): @ info.androidhive.slidingmenu.beritaterbaru.onstart(beritaterbaru.java:48) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.fragment.performstart(fragment.java:1724) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:918) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1062) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1044) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.fragmentmanagerimpl.dispatchstart(fragmentmanager.java:1858) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.activity.performstart(activity.java:5259) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.activitythread.performlaunchactivity(activitythread.java:2149) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2226) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.activitythread.access$700(activitythread.java:135) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.activitythread$h.handlemessage(activitythread.java:1397) 06-26 00:57:32.400: e/windowmanager(808): @ android.os.handler.dispatchmessage(handler.java:102) 06-26 00:57:32.400: e/windowmanager(808): @ android.os.looper.loop(looper.java:137) 06-26 00:57:32.400: e/windowmanager(808): @ android.app.activitythread.main(activitythread.java:4998) 06-26 00:57:32.400: e/windowmanager(808): @ java.lang.reflect.method.invokenative(native method) 06-26 00:57:32.400: e/windowmanager(808): @ java.lang.reflect.method.invoke(method.java:515) 06-26 00:57:32.400: e/windowmanager(808): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:777) 06-26 00:57:32.400: e/windowmanager(808): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:593) 06-26 00:57:32.400: e/windowmanager(808): @ dalvik.system.nativestart.main(native method) 06-26 00:57:32.560: i/process(808): sending signal. pid: 808 sig: 9
i have include class needed, still cant run it.
try this..
protected void doinbackground(void... unused) { current_page += 1; try { string urls = "http://www.ravaana.ml/webservice/" + current_page + ".xml"; url url = new url(urls); documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder db = dbf.newdocumentbuilder(); document doc = db.parse(new inputsource(url.openstream())); doc.getdocumentelement().normalize(); nodelist nodelist = doc.getelementsbytagname(key_item); (int = 0; < nodelist.getlength(); i++) { hashmap<string, string> map = new hashmap<string, string>(); node node = nodelist.item(i); element fstelmnt = (element) node; nodelist namelist = fstelmnt.getelementsbytagname(key_id); element nameelement = (element) namelist.item(0); namelist = nameelement.getchildnodes(); map.put(key_id, (((node) namelist.item(0)).getnodevalue())); element fstelmnt1 = (element) node; nodelist namelist1 = fstelmnt1.getelementsbytagname(key_judul); element nameelement1 = (element) namelist1.item(0); namelist1 = nameelement1.getchildnodes(); map.put(key_judul, (((node) namelist1.item(0)).getnodevalue())); element fstelmnt2 = (element) node; nodelist namelist2 = fstelmnt2.getelementsbytagname(key_berita); element nameelement2 = (element) namelist2.item(0); namelist2 = nameelement2.getchildnodes(); map.put(key_berita, (((node) nameelement2.item(0)).getnodevalue())); menuitems.add(map); } } catch (malformedurlexception e) { e.printstacktrace(); } catch (parserconfigurationexception e) { e.printstacktrace(); } catch (saxexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return null; }
Comments
Post a Comment