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

  • Home
  • SEARCH
  • 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 6363559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:03:11+00:00 2026-05-25T00:03:11+00:00

I have an app that has a viewflipper to keep tabs in view at

  • 0

I have an app that has a viewflipper to keep tabs in view at all times throughout the app, and a listview below the tabs. I’m trying to populate the list view with JSON strings from a web server, the web server is feeding JSON strings in the following format: [“X”,”Y”,”Z”]
So basically, I want to have the list view in list each string on a different row.

The app is launching ok, the list view just appears to be empty.
This is the tutorial I used: http://inchoo.net/mobile-development/android-development/simple-android-json-parsing-example-with-output-into-listactivity/
Here is the full code the main launching activity:

public class Activity extends TabActivity implements OnClickListener {

    Button doSomething;
    TabHost tabHost;
    ViewFlipper flipper;
    ListView listview;
    HttpResponse re;
    String json;
    JSONObject j;




    @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);



        setContentView(R.layout.tablayout_1);




        doSomething = (Button) findViewById(R.id.btn_do_something);
        doSomething.setOnClickListener(this);

        flipper = (ViewFlipper) findViewById(R.id.layout_tab_one);

        listview = (ListView) findViewById(R.id.listview);







       //@SuppressWarnings("unchecked")
       ListAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.fetch());



       listview.setAdapter(adapter);

        flipper.setOnClickListener(this);

        String tabname1 = getString(R.string.tabexample_tab1);
        String tabname2 = getString(R.string.tabexample_tab2);
        String tabname3 = getString(R.string.tabexample_tab3);
        String tabname4 = getString(R.string.tabexample_tab4);

        tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("tab1").setContent(R.id.layout_tab_one).setIndicator(tabname1));
        tabHost.addTab(tabHost.newTabSpec("tab2").setContent(R.id.layout_tab_two).setIndicator(tabname2));
        tabHost.addTab(tabHost.newTabSpec("tab3").setContent(R.id.layout_tab_three).setIndicator(tabname3));
        tabHost.addTab(tabHost.newTabSpec("tab4").setContent(R.id.layout_tab_four).setIndicator(tabname4));

        tabHost.setCurrentTab(0);




        listview.setOnItemClickListener(new OnItemClickListener(){
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                 flipper.showNext();


            }});




    }



    public ArrayList<String> fetch()
    {
        ArrayList<String> listItems = new ArrayList<String>();

        try {
            URL twitter = new URL(
                    "JSON.php");
            URLConnection tc = twitter.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));


            String line;


            while ((line = in.readLine()) != null) {




          //make sure youe String line is completely filled after that..
          if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
           {
          JSONArray jArray = new JSONArray(line);
          for (int i = 0; i < jArray.length(); i++) 
           {
              JSONObject jobj = jArray.getJSONObject(i);
             // also make sure you get the value from the jsonObject using some key
             // like, jobj.getString("country");

             listItems.add(jobj.toString()); 
           }
              }

            } 

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return listItems;
    }





    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }


}

Error in Log Cat:

 08-25 21:38:15.742: ERROR/InputDispatcher(81): channel '40a14e38 com.app.android/com.app.android.Activity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8

Update, here are the values of jArray as reported by Logcat:

08-26 16:49:07.246: VERBOSE/app(472): jarray value: [“Country1″,”Country2″,”Country3”]

These are the correct values!

Ok stepping into the loop, log out outputs the following:

08-26 16:59:55.756: WARN/System.err(506): org.json.JSONException: Value Country1 at 0 of type java.lang.String cannot be converted to JSONObject
08-26 16:59:55.756: WARN/System.err(506):     at org.json.JSON.typeMismatch(JSON.java:96)
08-26 16:59:55.766: WARN/System.err(506):     at org.json.JSONArray.getJSONObject(JSONArray.java:484)
08-26 16:59:55.775: WARN/System.err(506):     at com.app.android.Activity.fetch(Activity.java:165)
08-26 16:59:55.775: WARN/System.err(506):     at com.app.android.Activity.onCreate(eActivity.java:93)
08-26 16:59:55.786: WARN/System.err(506):     at android.app.Activity.performCreate(Activity.java:4397)
08-26 16:59:55.786: WARN/System.err(506):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
08-26 16:59:55.795: WARN/System.err(506):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
08-26 16:59:55.806: WARN/System.err(506):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
08-26 16:59:55.806: WARN/System.err(506):     at android.app.ActivityThread.access$500(ActivityThread.java:122)
08-26 16:59:55.815: WARN/System.err(506):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
08-26 16:59:55.815: WARN/System.err(506):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 16:59:55.826: WARN/System.err(506):     at android.os.Looper.loop(Looper.java:132)
08-26 16:59:55.826: WARN/System.err(506):     at android.app.ActivityThread.main(ActivityThread.java:4123)
08-26 16:59:55.836: WARN/System.err(506):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 16:59:55.836: WARN/System.err(506):     at java.lang.reflect.Method.invoke(Method.java:491)
08-26 16:59:55.846: WARN/System.err(506):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-26 16:59:55.855: WARN/System.err(506):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-26 16:59:55.855: WARN/System.err(506):     at dalvik.system.NativeStart.main(Native Method)
  • 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-05-25T00:03:12+00:00Added an answer on May 25, 2026 at 12:03 am

    I think your problem could be that your URL is just “JSON.php”. You dont specify the server this resides on (http://somewebsite.com/JSON.php). What happens when you set debug points and step through? Whats the value of the twitter URL after its created? My guess is that it cannot reach this “JSON.php”.

    EDIT: Try this:

    Instead of using

    JSONObject jobj = jArray.getJSONObject(i);
    

    Try

    String country = jArray.getString(i);
    listItems.add(country); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that has three tabs. They all do specific things. I
I have an app that has a centre view with two views off to
I have a small app that has a Render thread. All this thread does
I have an app that has a UINavigationController that pushes a UITabBarController into view.
I have an app that has a FK to USER. In ALL templates I
I have an app that has a main view that acts as a view
I have an app that has a lot of activities, all created with ONACTIVITYRESULT
I have a app that has multiple buttons that are all assigned images in
I have an app that has 2 tabs. Each tab loads an xml file
I have an App that has a thread handler receiving some socket data all

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.