php - volley not populating ListView with remote server -
my android app connects server , information database , fills in listview. works fine xampp on localhost. after uploading files server doesn't work. no error in log except.
d/volley: [1] 2.onerrorresponse: viewguidesactivity
but when run php file on web browser returns json data perfectly.
public class viewguidesactivity extends appcompatactivity { private static final string tag = viewguidesactivity.class.getsimplename(); private progressdialog pdialog; private list<guide> guidelist = new arraylist<guide>(); private listview listview; private customlistadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_view_guides); listview = (listview) findviewbyid(r.id.list); adapter = new customlistadapter(this, guidelist); listview.setadapter(adapter); pdialog = new progressdialog(this); // showing progress dialog before making http request pdialog.setmessage("loading..."); pdialog.show(); // creating volley request obj jsonarrayrequest moviereq = new jsonarrayrequest(appconfig.url_get_guide_list, new response.listener<jsonarray>() { @override public void onresponse(jsonarray response) { log.d(tag, response.tostring()); hidepdialog(); // parsing json (int = 0; < response.length(); i++) { try { jsonobject obj = response.getjsonobject(i); guide guide = new guide(); guide.setngno(obj.getstring("ngno")); guide.setemail(obj.getstring("email")); guide.setname(obj.getstring("name")); // adding movie movies array guidelist.add(guide); } catch (jsonexception e) { e.printstacktrace(); } } // notifying list adapter data changes // renders list view updated data adapter.notifydatasetchanged(); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error: " + error.getmessage()); hidepdialog(); } }); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); this.getsupportactionbar().setdisplayhomeasupenabled(true); // adding request request queue appcontroller.getinstance().addtorequestqueue(moviereq); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapter, view view, int position, long id) { guide newguide = guidelist.get(position); string email = newguide.getemail(); string ngno = newguide.getngno(); //system.out.println(email); intent = new intent(getapplicationcontext(), guidedetails.class); i.putextra("email", email); i.putextra("ngno", ngno); startactivity(i); } }); }
my php file:
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $sql = "select * guide"; $result = mysql_query($sql); $json = array(); if(mysql_num_rows($result)){ while($row=mysql_fetch_assoc($result)){ $json[]=$row; } } mysql_close($con); echo json_encode($json);
i'm aware i'm using deprecated methods, because refereed outdated tutorial, , im in process of converting php files use mysqli. first needed app working.
here json data:
http://srilankatouristguides.com/guidelist.php
i'm using same url in code. issue? cant figure out since works fine localhost. appreciated.
i managed fix it. not using mysqli causing connectivity issues. server not using deprecated methods code did not work. after converting php code mysqli, works. pointers guys!
Comments
Post a Comment