Android Studio with JSON URL does not give any result : <p>I have a situation whats getting annoying because i can't get a result.
Im trying to use a localhost JSON GET call. When i use this URL in my browser i get a JSON RESULT (not xml)
<a href="http://localhost:8080/Boxbackend/webresources/entities.movingboxes" rel="nofollow">http://localhost:8080/Boxbackend/webresources/entities.movingboxes</a></p>

<pre><code>[
{
"boxId": 1,
"boxName": "Stuff_1"
},
{
"boxId": 2,
"boxName": "Stuff_2"
},
{
"boxId": 3,
"boxName": "Stuff_3"
}
]
</code></pre>

<p>I used this netbeans tutorial to create a RESTful Web Service</p>

<p><a href="https://netbeans.org/kb/docs/websvc/rest.html" rel="nofollow">https://netbeans.org/kb/docs/websvc/rest.html</a></p>

<p>I used this example for android studio</p>

<p><a href="https://www.learn2crack.com/2013/10/android-asynctask-json-parsing-example.html" rel="nofollow">https://www.learn2crack.com/2013/10/android-asynctask-json-parsing-example.html</a></p>

<p>when the url is passing:</p>

<pre><code>JSONObject json = jParser.getJSONFromUrl(url);
</code></pre>

<p>json gets result null and and exception is fired
sometimes the exception : android.os.NetworkOnMainThreadException</p>

<p>instead of localhost i also uses sometimes 10.0.2.2</p>

<p>im getting a little frustrated.. </p>

<p>perhaps somebody can help</p>

<p>extra info:</p>

<p>the Mainactivity onCreate has a button</p>

<pre><code>Button box_list_button=(Button)findViewById(R.id.box_list_button);
        box_list_button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {    
                i = new Intent(getApplicationContext(), boxlist.class);
                startActivity(i);
            }
        });
</code></pre>

<p>the boxlist.class is like</p>

<pre><code>   public class boxlist extends Activity {

        ArrayList mobileArray;
        String [] mobileResult =  {"there is no data"};
        private static String url = "http://localhost:8080/Boxbackend/webresources/entities.movingboxes";
        JSONArray mbox = null;
        private static final String TAG_BNAME = "boxName";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.movingbox_layout);
            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(boxlist.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;
        } .......
</code></pre>
