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 8408857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:44:50+00:00 2026-06-09T23:44:50+00:00

Ok so i found this tutorial to parse mi JSON data into a ListView

  • 0

Ok so i found this tutorial to parse mi JSON data into a ListView (http://www.androidhive.info/2012/01/android-json-parsing-tutorial/), but i can´t manage to get it working, i don´t know what is going on and the error i keep getting is “exeption: your content must have a listview wich is ‘android.r.id.list'”, here is my code:

package com.example.tweev;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class Tweev extends ListActivity {

    // url to make request
    //private static String url = "http://api.androidhive.info/contacts/ ";
    private static String url = "http://www.tweevenvivo.com/service/Tweev.getActiveShows";

    // JSON Node names
    private static final String TAG_DATA = "data";
    private static final String TAG_TWEEVERS = "tweevers";
    private static final String TAG_ID = "id";
    private static final String TAG_CATEGORY = "category";
    private static final String TAG_DESCRIPTION = "description";
    private static final String TAG_NAME = "name";
    private static final String TAG_HASHTAG = "hashtag";
    private static final String TAG_CHANNELS = "channels";  //contains "operators", "hour and "operator name"
    private static final String TAG_OPERATORS = "operators";    //contains "channel" with "code"
    private static final String TAG_OPCHANNEL = "channel";
    private static final String TAG_OPCODE = "code";
    private static final String TAG_CHHOUR = "hour";
    private static final String TAG_CHNAME = "name";
    private static final String TAG_IMAGE_SMALL = "image_small";
    private static final String TAG_IMAGE = "image";
    private static final String TAG_SHOW_ID = "show_id";

    // tweevs JSONArray
    JSONArray tweevs = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tweev);
        TextView view = (TextView) findViewById(R.id.TextView01);
        String s="";
        for (int i=0; i < 500; i++) {
            s += "TEST "+i+" ";
        }
        view.setText(s);
        getData();
    }

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

    private void getData() {

        // Hashmap for ListView
        ArrayList<HashMap<String, String>> tweevList = new ArrayList<HashMap<String, String>>();

        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

        // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);

        //Log.d(TAG_DATA, "json " + json);

        try {
            // Getting Array of Contacts
            tweevs =  json.getJSONArray(TAG_DATA);

            Log.d(TAG_DATA, "tweevs " + tweevs);

            // looping through All tweevs
            for(int i = 0; i < 10; i++) {//tweevs.length()
                JSONObject c = tweevs.getJSONObject(i);

                // Storing each json item in variable
                String tweevers = c.getString(TAG_TWEEVERS);
                String id = c.getString(TAG_ID);
                String category = c.getString(TAG_CATEGORY);
                String description = c.getString(TAG_DESCRIPTION);
                String name = c.getString(TAG_NAME);
                String hashtag = c.getString(TAG_HASHTAG);
                //String channels = c.getString(TAG_CHANNELS);
                String image_small = c.getString(TAG_IMAGE_SMALL);
                String image = c.getString(TAG_IMAGE);
                String show_id = c.getString(TAG_SHOW_ID);

                // operators is again a JSON Object
                JSONArray channels = c.getJSONArray(TAG_CHANNELS);


                for(int j = 0; j < channels.length(); j++) {
                    JSONObject channel = channels.getJSONObject(j);
                    JSONArray operators = channel.getJSONArray(TAG_OPERATORS);

                    for(int k = 0; k < operators.length(); k++){
                        JSONObject operator = operators.getJSONObject(k);

                        String channelName = operator.getString(TAG_OPCHANNEL);
                        String channelCode = operator.getString(TAG_OPCODE);
                    }
                    String chhour = channel.getString(TAG_CHHOUR);
                    String chname = channel.getString(TAG_CHNAME);

                    //Log.d(TAG_DATA, "operator channel "+ k + " ::: " +channelName+" __CODE__ "+channelCode);
                    //Log.d(TAG_DATA, "channel hour "+ j + " ::: " +chhour+" --channel name-- "+chname);
                    //Log.d(TAG_DATA, "operators "+ j + " ::: " +channel+" --- "+code);
                    //Log.d(TAG_DATA, "operators "+ j + " ::: " +operators);
                }

                //Log.d(TAG_DATA, "tweev "+ i + " ::: " +channels);

                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put(TAG_ID, id);
                map.put(TAG_NAME, name);
                map.put(TAG_HASHTAG, hashtag);
                map.put(TAG_IMAGE_SMALL, image_small);

                // adding HashList to ArrayList
                tweevList.add(map);
            }

        } catch (JSONException e) {
            Log.d(TAG_DATA, "MOTHERFUCKER!");
            e.printStackTrace();
        }

        /**
         * Updating parsed JSON data into ListView
         * */
        ListAdapter adapter = new SimpleAdapter(this, tweevList,
                R.layout.list_items,
                new String[] { TAG_NAME, TAG_HASHTAG, TAG_IMAGE_SMALL }, new int[] {
                        R.id.name, R.id.name, R.id.hashtag });

        setListAdapter(adapter);

        // selecting single ListView item
        ListView lv = getListView();

        // Launching new screen on Selecting Single ListItem
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                /*
                // getting values from selected ListItem
                String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
                String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
                String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();

                // Starting new intent
                Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                in.putExtra(TAG_NAME, name);
                in.putExtra(TAG_EMAIL, cost);
                in.putExtra(TAG_PHONE_MOBILE, description);
                startActivity(in);
                */
            }
        });

    }


}

My guesses are that my XML file has something wrong, in their code i see that they use a layout for the OnCreate function and another one when creating the ListAdapter, i can´t see why is this and i don´t have a clue as to what are the contents of those layouts…

  • 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-09T23:44:52+00:00Added an answer on June 9, 2026 at 11:44 pm

    Your layout XML file should contain a ListView with id @android:id/list. Something like this

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <!-- Main ListView 
             Always give id value as list(@android:id/list)
        -->
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    
    </LinearLayout>
    

    The site that you mentioned above uses 3 different layouts – main.xml which is what the above pasted code refers to. It is used for the main activity.

    The second one is list_item.xml. This layout defines how each item in the list view appears. Here is the code for that layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">  
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <!-- Name Label -->
            <TextView
                android:id="@+id/name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#43bd00"
                android:textSize="16sp"
                android:textStyle="bold"
                android:paddingTop="6dip"
                android:paddingBottom="2dip" />
            <!-- Description label -->
            <TextView
                android:id="@+id/email"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#acacac"
                android:paddingBottom="2dip">
            </TextView>
            <!-- Linear layout for cost and price Cost: Rs.100 -->
            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <!-- Cost Label -->
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#5d5d5d"
                android:gravity="left"
                android:textStyle="bold"
                android:text="Mobile: " >
            </TextView>
            <!-- Price Label -->
            <TextView
                android:id="@+id/mobile"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#acacac" 
                android:textStyle="bold"
                android:gravity="left">
            </TextView>
            </LinearLayout>
        </LinearLayout>
    
    </LinearLayout>
    

    The third and final layout is single_list_item.xml. This layout defines how each individual item on the list is displayed once a single item on the list_item.xml is clicked.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">  
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <!-- Name Label -->
            <TextView
                android:id="@+id/name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#43bd00"
                android:textSize="16sp"
                android:textStyle="bold"
                android:paddingTop="6dip"
                android:paddingBottom="2dip" />
            <!-- Description label -->
            <TextView
                android:id="@+id/email"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#acacac"
                android:paddingBottom="2dip">
            </TextView>
            <!-- Linear layout for cost and price Cost: Rs.100 -->
            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <!-- Cost Label -->
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#5d5d5d"
                android:gravity="left"
                android:textStyle="bold"
                android:text="Mobile: " >
            </TextView>
            <!-- Price Label -->
            <TextView
                android:id="@+id/mobile"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#acacac" 
                android:textStyle="bold"
                android:gravity="left">
            </TextView>
            </LinearLayout>
        </LinearLayout>
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this tutorial and am trying to implement it in my project http://www.androiddevblog.net/android/playing-audio-in-android
Im trying to understand what a functor is, i found this tutorial/example: http://en.wikibooks.org/wiki/Haskell/Solutions/Applicative_Functors data
I found this tutorial which pretty much does exactly what I want: http://webstutorial.com/jquery-popup-jquery-slide-popup/jquery Except
I'm running through this tutorial found here: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_from_multiple_tables.htm which teaches how to pass a
I was reading this tutorial from the DNN website http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/2675/DotNetNuke-Skinning-101-Part-2.aspx I found the tutorial
I have found this tutorial online http://net.tutsplus.com/tutorials/php/creating-a-php5-framework-part-1/ I have created myself a simple sort
I used to have trouble parsing json, before I found a really good tutorial
So I found this: http://tiles.apache.org/framework/tutorial/advanced/nesting-extending.html Here is the example: <definition name=myapp.homepage template=/layouts/classic.jsp> <put-attribute name=title
I found this tutorial http://sqllessons.com/categories.html and I want to use the described method as
I found This tutorial for resize background of button . i change this for

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.