Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Exception no result returned
    primarykey
    data
    text
    <p>Android application that receives ID ,Name and Email from PHP file ID , Name , Email sent as JSON response to Android Application , the problem is when i click get data no data is received and i get an exception in the LogCat here is my code,PHP file and stack trace MainActivity</p> <pre><code> package com.example.colcheck; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.example.colcheck.Library.*; public class MainActivity extends Activity { TextView uid; TextView name1; TextView email1; Button Btngetdata; //URL to get JSON Array private static String url = "http://localhost/new/check2.php"; //JSON Node Names private static final 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 void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Btngetdata = (Button)findViewById(R.id.getdata); Btngetdata.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new JSONParse().execute(); } }); } private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt; { private ProgressDialog pDialog; @Override protected void onPreExecute() { super.onPreExecute(); uid = (TextView)findViewById(R.id.uid); name1 = (TextView)findViewById(R.id.name); email1 = (TextView)findViewById(R.id.email); pDialog = new ProgressDialog(MainActivity.this); pDialog.setMessage("Getting Data ..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected JSONObject doInBackground(String... args) { JSONParser jParser = new JSONParser(); // Getting JSON from URL JSONObject json = jParser.getJSONFromUrl(url); return json; } @Override protected void onPostExecute(JSONObject json) { pDialog.dismiss(); try { System.out.println("JSON Response : "+json.toString().trim()); String id=""; String name=""; String email=""; if(json.has("id")) id = json.getString("id"); if(json.has("name")) name = json.getString("name"); if(json.has("TAG_EMAIL")) email = json.getString("TAG_EMAIL"); //Set JSON Data in TextView uid.setText(id); name1.setText(name); email1.setText(email); } catch (JSONException e) { e.printStackTrace(); } } } } </code></pre> <p>PHP file with json response</p> <pre><code> &lt;?php $con=mysqli_connect("localhost","root","123","pet_home"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM users WHERE username='test' AND password='123'"); $row_cnt = mysqli_num_rows($result); if($row_cnt&gt;0){ $row = mysqli_fetch_array($result); $data = array('success'=&gt;true, 'user'=&gt;array("TAG_ID" =&gt; $row['id'], "TAG_NAME"=&gt; $row['name'], "TAG_EMAIL" =&gt;$row['email'])); }else{ $data = array('success'=&gt;false); } header('Content-Type: application/json'); echo json_encode($data); mysqli_close($con); ?&gt; </code></pre> <p>After doing this no response comes back to android app Here is stacktrace seems like there is an exception</p> <pre><code>11-30 17:06:13.679: I/System.out(3474): JSON Response : {"TAG_USER":{"id":"OFF","TAG_EMAIL":"OFF","name":"OFF"},"success":true} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload