Moudiz
Moudiz

Reputation: 7377

what is the cause of org.json.JSONException: No value for url

this is the code .ofcourse the url is returning data.

protected void showList(){
    try {
        JSONObject jsonObj = new JSONObject(myJSON);
        peoples = jsonObj.getJSONArray(TAG_RESULTS);

        for(int i=0;i<peoples.length();i++){
            JSONObject c = peoples.getJSONObject(i);
            String id = c.getString(TAG_ID);
            String url = c.getString(TAG_URL); 
            Listitem.add(new Listitem(id,url));
        }

        GridViewAdapter adapter = new GridViewAdapter(this, R.layout.grid_item_layout, Listitem);
     //   gridView.setAdapter(gridAdapter); 

       list.setAdapter(adapter);

    } catch (JSONException e) {
        e.printStackTrace();
    }

asycntask and url

 protected String doInBackground(String... params) {
                DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
                HttpPost httppost = new HttpPost("http://justedhak.comlu.com/get-data.php");

                // Depends on your web service
                httppost.setHeader("Content-type", "application/json");

                InputStream inputStream = null;
                String result = null;
                try {
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();

                    inputStream = entity.getContent();
                    // json is UTF-8 by default
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();

                    String line = null;
                    while ((line = reader.readLine()) != null)
                    {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                } catch (Exception e) {
                    // Oops
                }
                finally {
                    try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
                }
                return result;
            }

Upvotes: 1

Views: 353

Answers (2)

abozaid
abozaid

Reputation: 967

Make sure that Your TAG_URL must be like that

final String TAG_URL = "path";
String url = c. getString (TAG_URL); 

Upvotes: 1

Amalo
Amalo

Reputation: 772

Your url is http://justedhak.comlu.com/get-data.php", you didn,t mentioned any json api to get data from it u must do something like http://justedhak.comlu.com/get-data.php/apiName?param1=...

Upvotes: 1

Related Questions