Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:20:18+00:00 2026-06-09T18:20:18+00:00

I am trying to display a JSONObject that I have converted to string in

  • 0

I am trying to display a JSONObject that I have converted to string in an EditText field in my android app. When I run the app it loads without error but my EditText field is empty. I also tried to do System.out.println(name); but nothing printed to the console so my best guess is nothing is actually stored there and I am not sure why.
Here is my main file

package com.apitest.rottentomatoestest;

import android.os.Bundle;    
import java.util.ArrayList;
import java.util.HashMap;    
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;    
import org.json.*;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;    
import android.widget.TextView;
import android.widget.EditText;
import java.util.logging.*;

public class Main extends Activity {        

    private static String url = "http://api.rottentomatoes.com/api/public/v1.0/movies/770672123/cast.json?apikey=3p9ehnhzbxwpd6mk8fnncf67";

    private static final String TAG_CAST = "cast";
    private static final String TAG_ID = "id";
    private static final String TAG_NAME = "name";
    private static final String TAG_CHARACTERS = "characters";

    EditText display;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        try
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.mainlayout);
            JSONArray cast = null; 
            JSONParser jParser = new JSONParser();
            JSONObject jSon = jParser.getJSONFromUrl(url);              
            display = (EditText) findViewById(R.id.display);            

            try
            {
                cast = jSon.getJSONArray(TAG_CAST);                 
                for(int i=0; i < cast.length(); i++){
                    JSONObject c = cast.getJSONObject(i);                       
                    String name = c.getString(TAG_NAME);                        
                    display.setText(name); 
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        catch (Exception e){
            Log.e("ERROR", "ERROR IN CODE" + e.toString());
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.mainlayout, menu);
        return true;
    }
}

This is my JSONParser class

package com.apitest.rottentomatoestest;

import java.io.*;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.*;

import android.util.Log;

public class JSONParser {

    static InputStream inputStream = null;
    static JSONObject jObject = null;
    static String jSon = "";

    public JSONParser() {
        // TODO Auto-generated constructor stub
    }

    public JSONObject getJSONFromUrl(String url){

        //Make HTTP Request
        try {
            //defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            inputStream = httpEntity.getContent();

        } catch (UnsupportedEncodingException e){
            e.printStackTrace();
        } catch (ClientProtocolException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
            StringBuilder stringBuilder = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null){
                stringBuilder.append(line + "\n");
            }
            inputStream.close();
            jSon = stringBuilder.toString();
        } catch (Exception e){
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        //try to parse the string to JSON Object
        try {
            jObject = new JSONObject(jSon);
        } catch (JSONException e){
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        //return JSON String
        return jObject;
    }    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:20:20+00:00Added an answer on June 9, 2026 at 6:20 pm
     cast = jSon.getJSONArray(TAG_CAST);
    
      for(int i=0; i < cast.length(); i++){
           JSONObject c = cast.getJSONObject(i);
    
            String name = c.getString(TAG_NAME);
    
            display.setText(name);
    }
    

    you’d better check the last value of name

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

recently I been trying to create an android app that uses JSON Objects to
trying to display data only after variables have been set. $(document).ready(function () { function
I am trying to display data that I am getting from server through json.
I have an array of Person pocos, populated below. I'm trying display them alphabetically
Im trying to display the image i have coming from an intent.putExtra on a
Im trying to display this listview, but I keep getting a: 07-17 21:14:22.233: ERROR/AndroidRuntime(349):
I am trying to retrieve data from mysql then display it on android listview.
I am trying to create a JSON String in the Android application. JSONArray jArrayFacebookData
i'm using MVC2, and am trying to display a friendly error message to the
Im trying to display text but that isnt working. I create a dynamic text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.