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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:46:26+00:00 2026-06-04T05:46:26+00:00

I’m pretty new to Android programming so any help would be great :) I’m

  • 0

I’m pretty new to Android programming so any help would be great 🙂
I’m trying to get some dummy data remotely, parse the json response and display it within a listview.

This is the xml layout file i’m trying to use with the list activity:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/list"
    />
</LinearLayout>

This is my http search activity:-

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class searchResultActivity extends ListActivity {

    ListView listview;
    String result = null;
    InputStream is = null;
    StringBuilder sb = null;
    String url;
    String fd_name;
    ArrayList<String> listItems;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        /*setContentView(R.layout.test);
        listview = (ListView)findViewById(R.id.list);*/
        url = "http://pjchambers.comuf.com/index.php";
        new getData().execute();
    }

    public class getData extends AsyncTask<String, Void, ArrayList<String>> {

        protected ArrayList<String> doInBackground(String...urls) {
            // TODO Auto-generated method stub
            listItems = new ArrayList<String>();

            try {
                // Set of http statements setting up the connections to the php
                // and database
                HttpClient httpclient = new DefaultHttpClient();
                HttpGet httpget = new HttpGet(url);
                HttpResponse response = httpclient.execute(httpget);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
            } catch (Exception e) {
                Log.e("log_tag", "Error in http connection" + e.toString());
            }

            // convert response to string
            try {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is, "iso-8859-1"), 8);
                sb = new StringBuilder();
                sb.append(reader.readLine() + "\n");
                String line = "0";
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();
            } catch (Exception e) {
                Log.e("log_tag", "Error converting result " + e.toString());
            }

            // paring data
            try {
                JSONArray jArray = new JSONArray(result);
                JSONObject json_data = null;
                for (int i = 0; i < jArray.length(); i++) {
                    json_data = jArray.getJSONObject(i);
                    fd_name = json_data.getString("Name");
                    listItems.add(fd_name);
                }
            } catch (JSONException e1) {
                Toast.makeText(getBaseContext(), "No Results Found",
                        Toast.LENGTH_LONG).show();
            } catch (ParseException e1) {
                e1.printStackTrace();
            }

            Log.d("debug", "- " + listItems.toString());
            return listItems;
        }

        protected void doPostExecute() {
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                    searchResultActivity.this, android.R.layout.simple_list_item_1, R.id.list, listItems);
            setListAdapter(adapter);
        }

    }

}

I’ve spent hours trying different methods and approaches, using a few different online tutorials but they all end in the same result. As it stands the app works but the displays are displayed; however if i declare the layout in the onCreate methods the app crashes. any help or advice would be must appreciated, a fresh set of eyes might notice the issue(s) straight away

This is the logcat after I uncommented the two statements

05-22 12:12:20.234: D/debug(631): - [The Arena, Empire]
05-22 12:12:42.004: I/dalvikvm(691): threadid=3: reacting to signal 3
05-22 12:12:42.244: I/dalvikvm(691): Wrote stack traces to '/data/anr/traces.txt'
05-22 12:12:42.404: D/gralloc_goldfish(691): Emulator without GPU emulation detected.
05-22 12:12:48.415: I/dalvikvm(691): threadid=3: reacting to signal 3
05-22 12:12:48.424: I/dalvikvm(691): Wrote stack traces to '/data/anr/traces.txt'
05-22 12:12:50.595: D/AndroidRuntime(691): Shutting down VM
05-22 12:12:50.595: W/dalvikvm(691): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-22 12:12:50.614: E/AndroidRuntime(691): FATAL EXCEPTION: main
05-22 12:12:50.614: E/AndroidRuntime(691): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.barcrawl/com.project.barcrawl.searchResultActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.os.Looper.loop(Looper.java:137)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-22 12:12:50.614: E/AndroidRuntime(691):  at java.lang.reflect.Method.invokeNative(Native Method)
05-22 12:12:50.614: E/AndroidRuntime(691):  at java.lang.reflect.Method.invoke(Method.java:511)
05-22 12:12:50.614: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-22 12:12:50.614: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-22 12:12:50.614: E/AndroidRuntime(691):  at dalvik.system.NativeStart.main(Native Method)
05-22 12:12:50.614: E/AndroidRuntime(691): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-22 12:12:50.614: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.Activity.setContentView(Activity.java:1835)
05-22 12:12:50.614: E/AndroidRuntime(691):  at com.project.barcrawl.searchResultActivity.onCreate(searchResultActivity.java:41)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.Activity.performCreate(Activity.java:4465)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-22 12:12:50.614: E/AndroidRuntime(691):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-22 12:12:50.614: E/AndroidRuntime(691):  ... 11 more
05-22 12:12:51.004: I/dalvikvm(691): threadid=3: reacting to signal 3
05-22 12:12:51.024: I/dalvikvm(691): Wrote stack traces to '/data/anr/traces.txt'
  • 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-04T05:46:28+00:00Added an answer on June 4, 2026 at 5:46 am

    Your id in the XML should id="@android:id/list" then it should work. In your code a new id is created as part of “your” R.class which is different from android.R.id.list. Therefore the list view cannot be found and consequently the exception is thrown.

    Also the third parameter of the ArrayAdapter constructor is supposed to be the id of the text resource to fill with the data. You are passing R.id.list which is wrong. For the resource defined by android.R.id.simple_list_item_1 it should be android.R.id.text1 if I’m not mistaken.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

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.