Note that there are some explanatory texts on larger screens.

plurals
  1. POJAVA ANDROID:Reading Php Json values, Eclipse dont see the error but it doesnt work
    primarykey
    data
    text
    <p>Reading Php Json values, Eclipse dont see the error but it doesnt work. Im becoming crazy because it must run, can you help me? When i execute it nothing happens. </p> <p>This is the java activity code:</p> <pre><code> package com.json.php; import android.app.Activity; import android.os.Bundle; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import android.widget.TextView; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class JSONExampleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://iatek.eu/sys/getsms.php"); TextView textView = (TextView)findViewById(R.id.textView1); try { HttpResponse response = httpclient.execute(httppost); String jsonResult = inputStreamToString(response.getEntity().getContent()).toString(); JSONObject obj = new JSONObject(jsonResult); JSONArray jsonArray = obj.getJSONArray("posts"); /*Para hacer prueba accedo a un registro concreto en este caso el 3*/ JSONObject childJSONObject = jsonArray.getJSONObject(3); String username = childJSONObject.getString("username"); String sms = childJSONObject.getString("sms"); String fcat = childJSONObject.getString("fcat"); textView.setText(""+sms+"--" + username); /* para hacer pruebas lo he comentado for (int i = 0; i &lt; jsonArray.length(); i++) { JSONObject childJSONObject = jsonArray.getJSONObject(i); String username = childJSONObject.getString("username"); String sms = childJSONObject.getString("sms"); String fcat = childJSONObject.getString("fcat"); textView.setText(""+sms+"--" + username); }*/ } catch (JSONException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private StringBuilder inputStreamToString(InputStream is) { String rLine = ""; StringBuilder answer = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); try { while ((rLine = rd.readLine()) != null) { answer.append(rLine); } } catch (IOException e) { e.printStackTrace(); } return answer; } } </code></pre> <p>and here is the json code into iatek.eu/sys/getsms.php</p> <pre><code>{"posts":[{"cid":"11","username":"Livi","sms":"ag","fto":"","fcat":"cat"},{"cid":"10","username":"Sumone","sms":"","fto":"","fcat":""},{"cid":"9","username":"R2D2","sms":"dw","fto":"wd","fcat":"wd"},{"cid":"5","username":"Roy","sms":"sa","fto":"sa","fcat":"sa"},{"cid":"12","username":"Charles","sms":"ag","fto":"","fcat":"cat"},{"cid":"13","username":"Clarck","sms":"age","fto":"","fcat":"cat"}]} </code></pre> <p>can someone tell me where is the mistake? thanks</p>
    singulars
    1. This table or related slice is empty.
    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