Note that there are some explanatory texts on larger screens.

plurals
  1. POjson to android could not connect to database
    text
    copied!<p>i'm trying to parse the information of a json array into android. I use the below code, and i get info from a webservice, if i open the php file it's all ok, but in android i get could not connect to database. I do have set permissions to access the internet...</p> <p>Here is the code i use:</p> <pre><code> @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); StrictMode.enableDefaults(); //STRICT MODE ENABLED resultView = (TextView) findViewById(R.id.result); getData(); } public void getData(){ String result = ""; InputStream isr = null; try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://192.168.10.28/albana/getAllCustomers.php"); //YOUR PHP SCRIPT ADDRESS HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); isr = entity.getContent(); } catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); resultView.setText("Couldnt connect to database"); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } isr.close(); result=sb.toString(); } catch(Exception e){ Log.e("log_tag", "Error converting result "+e.toString()); } //parse json data try { String s = ""; JSONArray jArray = new JSONArray(result); for(int i=0; i&lt;jArray.length();i++){ JSONObject json = jArray.getJSONObject(i); s = s + "Name : "+json.getString("FirstName")+" "+json.getString("LastName")+"\n"+ "Age : "+json.getInt("Age")+"\n"+ "Mobile Using : "+json.getString("Mobile")+"\n\n"; } resultView.setText(s); } catch (Exception e) { // TODO: handle exception Log.e("log_tag", "Error Parsing Data "+e.toString()); } } </code></pre> <p>I get the message "Could not connect to database"; No errors on the Log Cat... Please someone suggest me..</p>
 

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