Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is happening because you are trying to perform network operations on the UI thread. You need to use a background thread for network operations.</p> <p>Use an <code>AsyncTask</code> as follows:</p> <pre><code>public class MainActivity extends Activity { //URL to get JSON Array private static String url = "http://api.worldbank.org/countries/ir?format=json"; //JSON node Names private static final String PAGE = "page"; private static final String VALUE = "value"; private static final String NAME = "name"; private static final String GEO = "region"; JSONArray page = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new GetJSONTask().execute(url); // do not parse here.. ... ... } ... ... class GetJSONTask extends AsyncTask&lt;String, Void, JSONObject&gt; { protected JSONObject doInBackground(String... urls) { try { JSONParser jParser = new JSONParser(); return jParser.getJSONFromUrl(urls[0]); } catch (Exception e) { return null; } } protected void onPostExecute(JSONObject json) { // do all the parsing here: try { //Getting JSON Array page = json.getJSONArray(PAGE); JSONObject c = page.getJSONObject(0); //Sorting JSON item in a Variable String value = c.getString(VALUE); String name = c.getString(NAME); String geo = c.getString(GEO); //Importing to TextView final TextView id1 = (TextView) findViewById(R.id.id); final TextView name1 = (TextView) findViewById(R.id.name); final TextView geo1 = (TextView) findViewById(R.id.geo); //set JSON Data in TextView id1.setText(value); name1.setText(name); geo1.setText(geo); } catch (JSONException e) { e.printStackTrace(); } } } } </code></pre> <p>Ref: <a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/os/AsyncTask.html</a></p> <p><strong>update</strong> another bug spotted, update XML</p> <pre><code>&lt;TextView android:id="@+id/id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/name" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; ... ... </code></pre> <p>You cannot have two views and say <code>A below B</code>, then <code>B below A</code> that will <a href="https://stackoverflow.com/q/17949973/827110">cause problems!</a></p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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