android - send a consult to one url but the JSON return is null always -


I have a problem, I try to extract the information of a php in my server, but the reaction is always nonsensical

I use the next code, I'm new to Android, but I think the PC does not send anything to the app

  Public class increases main activity activity { // URL JSON Array Private Static String URL = "http://10.69.44.108/odin/mobile/json/" Getting For; // JSON node name personal constant last string TAG_USER = "user"; Private static final string TAG_ID = "id"; Private static final string TAG_NAME = "name"; Private static final string TAG_EMAIL = "email"; JSONArray user = null; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); // New JSON Parser JSONParser jParser = New JSONParser () is making; // JSONObject json = get json from jParser.getJSONFromUrl (url); Try {// JSON Array user = json.getJSONArray (TAG_USER); JSONObject c = user.getJSONObject (0); // stored a JSON item in a variable string id = j.getString (TAG_ID); String name = c.getString (TAG_NAME); String Email = C.Great String (TAG_EMAIL); // Import textView final textView uid = (TextView) findViewById (R.id.uid); Last textview name 1 = (text view) Find VViBiID (RID name); Last TextView Email 1 = (TextView) Find VVBID (RID .mail); // Set the JSON data in TextView uid.setText (id); Name1.setText (name); Email1.setText (email); } Hold (JasonX Express E) {e.printStackTrace (); In Android, you do not have permission to perform a network operation on the main thread:  

/ P>

You can not:

  // get JSON from JSONObject json = jParser.getJSONFromUrl (url); In  

onCreate , you must keep it in one.


You can make it fast and dirty (not tested!):

  // Import textView last textView uid = (TextView) findViewById (R .id.uid); Last textview name 1 = (text view) Find VViBiID (RID name); Last TextView Email 1 = (TextView) Find VVBID (RID .mail); New AsyncTask & lt; String, JSONObject, JSONObject & gt; () {@ Override protected JSONObject doInBackground (string ... url) {// new JSON parser JSONParser jParser = new JSONParser () is making; // get JSON from URL JSONObject json = new JSONObject (); Try {json = jParser.getJSONFromUrl (url []); } Hold (JSOXExation E) {// Returning to something} Back Jason; } Get Zero (JSONObject json) on safe exchequer {try {// JSON Array user = json.getJSONArray (TAG_USER); JSONObject c = user.getJSONObject (0); // stored a JSON item in a variable string id = j.getString (TAG_ID); String name = c.getString (TAG_NAME); String Email = C.Great String (TAG_EMAIL); // Set the JSON data in TextView uid.setText (id); Name1.setText (name); Email1.setText (email); } Hold (JasonX Express E) {e.printStackTrace (); }}}. Execute (url);  

Comments