java - Why is my list getting null values? -



java - Why is my list getting null values? -

i have project need parse json google places api list getting null values or no values @ all. in myactivity.java in onpostexecute method when seek next not parsing values , returning them. creating objects in jsonparser class not getting them in onpostexecute method?

placelist = jsonparser.parsefeed(result);

here code:

myactivity.java public class myactivity extends activity { // create references ui elements edittext urltext; textview textview; progressbar pb; // create reference list's needed info list<mytask> tasks; list<places> placelist; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my); // ui elements id urltext = (edittext) findviewbyid(r.id.myurl); textview = (textview) findviewbyid(r.id.mytext); pb = (progressbar) findviewbyid(r.id.progressbar); // set progress bar invisible pb.setvisibility(view.invisible); //initiate tasks tasks = new arraylist<>(); // create text view scrollable textview.setmovementmethod(new scrollingmovementmethod()); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.my, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); homecoming id == r.id.action_settings || super.onoptionsitemselected(item); } // method when button clicked public void myclick(view view) { // create string grab text of edit text string mystring = urltext.gettext().tostring(); // replace spaces + encode url string encodedstring = mystring.replace(" ", "+"); //check see if online , if go on json info if not toast message telling user no connection if (isonline()) { requestdata("https://maps.googleapis.com/maps/api/place/textsearch/json?query=" + encodedstring + "&key=aizasyb9iow6wf4fwbodutzyiu_mxsbfwm5imoi"); } else toast.maketext(this, "network isn't available", toast.length_short).show(); } // method update th ui protected void updatedisplay() { if (placelist != null) { (places place : placelist) { textview.append(place.getname()); } } } // method check net connectivity protected boolean isonline() { connectivitymanager cm = (connectivitymanager) getsystemservice(context.connectivity_service); networkinfo netinfo = cm.getactivenetworkinfo(); homecoming netinfo != null && netinfo.isconnectedorconnecting(); } // method info async task private void requestdata(string uri) { mytask task = new mytask(); task.execute(uri); } // async task method network action in private class mytask extends asynctask<string, string, string> { @override protected void onpreexecute() { if (tasks.size() == 0) { // set progress bar visible while async task running pb.setvisibility(view.visible); } // add together task tasks.add(this); } @override protected string doinbackground(string... params) { homecoming httpmanager.getdata(params[0]); } @override protected void onpostexecute(string result) { placelist = jsonparser.parsefeed(result); log.v("message:", string.valueof(placelist)); updatedisplay(); tasks.remove(this); if (tasks.size() == 0) { // remove progress bar visibility ui pb.setvisibility(view.invisible); } } @override protected void onprogressupdate(string... values) { //updatedisplay(values[0]); } } } jsonparser.java public class jsonparser { public static list<places> parsefeed(string content) { jsonobject myobj; seek { myobj = new jsonobject(content); jsonarray result = myobj.getjsonarray("results"); list<places> placelist = new arraylist<>(); (int = 0; <= result.length(); i++) { jsonobject obj = result.getjsonobject(i); places place = new places(); place.setname(obj.getstring("name")); // place.setformatted_address(obj.getstring("formatted_address")); // place.settypes(obj.getstring("types")); //place.setphotos(obj.getstring("photos")); placelist.add(place); } homecoming placelist; } grab (jsonexception e) { e.printstacktrace(); homecoming null; } } } places.java public class places { private string pname; private string ptypes; private string pformatted_address; private string pphotos; public places(){ pname =""; ptypes =""; pformatted_address = ""; pphotos=""; } public places (string _name, string _types, string _formatted_address, string _photos){ pname = _name; ptypes =_types; pformatted_address = _formatted_address; pphotos = _photos; } public string getname() { homecoming pname; } public void setname(string name) { pname = name; } public string gettypes() { homecoming ptypes; } public void settypes(string types) { ptypes= types; } public string getformatted_address() { homecoming pformatted_address; } public void setformatted_address(string formatted_address) { pformatted_address=formatted_address; } public string getphotos() { homecoming pphotos; } public void setphotos(string photos) { pphotos= photos; } } activity_my.xml <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context=".myactivity"> <edittext android:id="@+id/myurl" android:inputtype="texturi" android:hint="@string/hint" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <button android:id="@+id/mybutton" android:text="@string/enter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="myclick" /> <textview android:id="@+id/mytext" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <imageview android:id="@+id/image_view" android:contentdescription="@string/hint" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <progressbar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/progressbar" android:layout_gravity="center_horizontal" /> </linearlayout> json { "html_attributions": [], "results": [ { "formatted_address": "los angeles, ca, usa", "geometry": { "location": { "lat": 34.0522342, "lng": -118.2436849 }, "viewport": { "northeast": { "lat": 34.3373061, "lng": -118.1552891 }, "southwest": { "lat": 33.7036917, "lng": -118.6681759 } } }, "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png", "id": "7f7b7d8118ae8db8ed3f541159ac928c484d12ad", "name": "los angeles", "place_id": "chije9on3f3hwoar9ahgjw_fl-i", "reference": "coqbfwaaadoao2di1kxx7js6g1utfzjgmiioj3zoggn26ymdjslpkz9szburmdukytjntmrk8iswwhnpuj7eyvbhl0txifz-ys4qizi7eea7olh5wnzude3iyd9icq_mrigwxqop0_wssar9qu57wg8vtqzn7tqheurmsc5zarkjgfvk-unjeharvd57imh0qkfsjchx7rfbghst3gv5rcklbl_-9kjaalz3kuny5a", "types": [ "locality", "political" ] } ], "status": "ok" }

i think parsing 1 more object should, throw exception , homecoming null:

// replace <= < (int = 0; <= result.length(); i++) { // (...) }

java android

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -