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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:52:37+00:00 2026-06-01T15:52:37+00:00

I am having a problem getting this code to work. Basically I Go from

  • 0

I am having a problem getting this code to work.

Basically I Go from one list activity to another and pass the text from a list item through the intent of the activity to the new list view, then retrieve that text in the new list activity and then preform a http request based on value of that list item.

Log Cat

04-05 17:47:32.370: E/AndroidRuntime(30135): FATAL EXCEPTION: main
04-05 17:47:32.370: E/AndroidRuntime(30135): java.lang.ClassCastException:android.widget.LinearLayout
04-05 17:47:32.370: E/AndroidRuntime(30135): at com.thickcrustdesigns.ufood.CatogPage$1.onItemClick(CatogPage.java:66)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.widget.ListView.performItemClick(ListView.java:3731)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1959)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.os.Handler.handleCallback(Handler.java:587)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.os.Handler.dispatchMessage(Handler.java:92)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.os.Looper.loop(Looper.java:130)
04-05 17:47:32.370: E/AndroidRuntime(30135): at android.app.ActivityThread.main(ActivityThread.java:3691)
04-05 17:47:32.370: E/AndroidRuntime(30135): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 17:47:32.370: E/AndroidRuntime(30135): at java.lang.reflect.Method.invoke(Method.java:507)
04-05 17:47:32.370: E/AndroidRuntime(30135): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-05 17:47:32.370: E/AndroidRuntime(30135): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-05 17:47:32.370: E/AndroidRuntime(30135): at dalvik.system.NativeStart.main(Native Method)

ListActivity 1

package com.thickcrustdesigns.ufood;

import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class CatogPage extends ListActivity {

    ListView listView1;
    Button btn_bk;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.definition_main);

        btn_bk = (Button) findViewById(R.id.btn_bk);

        listView1 = (ListView) findViewById(android.R.id.list);

        ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();

        nvp.add(new BasicNameValuePair("request", "categories"));

        ArrayList<JSONObject> jsondefs = Request.fetchData(this, nvp);

        String[] defs = new String[jsondefs.size()];

        for (int i = 0; i < jsondefs.size(); i++) {
            try {
                defs[i] = jsondefs.get(i).getString("Name");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        uFoodAdapter adapter = new uFoodAdapter(this, R.layout.definition_list,
                defs);

        listView1.setAdapter(adapter);
        ListView lv = getListView();
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                TextView tv = (TextView) view;
                String p = tv.getText().toString();
                Intent i = new Intent(getApplicationContext(), Results.class);
                i.putExtra("category", p);
                startActivity(i);
            }
        });

        btn_bk.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                Intent i = new Intent(getApplicationContext(),
                        UFoodAppActivity.class);
                startActivity(i);
            }
        });

    }

}


**ListActivity 2**

package com.thickcrustdesigns.ufood;

    import java.util.ArrayList;
    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;
    import org.json.JSONException;
    import org.json.JSONObject;
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.widget.ListView;

    public class Results extends ListActivity {

    ListView listView1;

    enum Category {
        Chicken, Beef, Chinese, Cocktails, Curry, Deserts, Fish, ForOne {
            public String toString() {
                return "For One";
            }
        },
        Lamb, LightBites {
            public String toString() {
                return "Light Bites";
            }
        },
        Pasta, Pork, Vegetarian
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.definition_main);

        listView1 = (ListView) findViewById(android.R.id.list);

        Bundle data = getIntent().getExtras();
        String category = data.getString("category");

        Category cat = Category.valueOf(category);

        String value = null;

        switch (cat) {
        case Chicken:
            value = "Chicken";
            break;
        case Beef:
            value = "Beef";
            break;
        case Chinese:
            value = "Chinese";
            break;
        case Cocktails:
            value = "Cocktails";
            break;
        case Curry:
            value = "Curry";
            break;
        case Deserts:
            value = "Deserts";
            break;
        case Fish:
            value = "Fish";
            break;
        case ForOne:
            value = "ForOne";
            break;
        case Lamb:
            value = "Lamb";
            break;
        case LightBites:
            value = "LightBites";
            break;
        case Pasta:
            value = "Pasta";
            break;
        case Pork:
            value = "Pork";
            break;
        case Vegetarian:
            value = "Vegetarian";
        }

        ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();

        nvp.add(new BasicNameValuePair("request", "category"));

        nvp.add(new BasicNameValuePair("cat", value));

        ArrayList<JSONObject> jsondefs = Request.fetchData(this, nvp);

        String[] defs = new String[jsondefs.size()];

        for (int i = 0; i < jsondefs.size(); i++) {
            try {
                defs[i] = jsondefs.get(i).getString("Name");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        uFoodAdapter adapter = new uFoodAdapter(this, R.layout.definition_list,
                defs);
        listView1.setAdapter(adapter);

           }

       }

Request

package com.thickcrustdesigns.ufood;

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.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class Request {

    @SuppressWarnings("null")
    public static ArrayList<JSONObject> fetchData(Context context,
            ArrayList<NameValuePair> nvp) {
        ArrayList<JSONObject> listItems = new ArrayList<JSONObject>();
        InputStream is = null;
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(
                    "http://co350-11d.projects02.glos.ac.uk/php/database.php");
            httppost.setEntity(new UrlEncodedFormEntity(nvp));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection" + e.toString());
        }

        // convert response to string

        String result = "";
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            InputStream stream = null;
            StringBuilder sb = null;

            while ((result = reader.readLine()) != null) {
                sb.append(result + "\n");
            }

            stream.close();
            result = sb.toString();

        } catch (Exception e) {
            Log.e("log_tag", "Error converting result " + e.toString());
        }

        try {
            JSONArray jArray = new JSONArray(result);

            for (int i = 0; i < jArray.length(); i++) {

                JSONObject jo = jArray.getJSONObject(i);

                listItems.add(jo);

            }

        } catch (Exception e) {
            Toast.makeText(context.getApplicationContext(), "None Found!",
                    Toast.LENGTH_LONG).show();

        }
        return listItems;

    }

}

package com.thickcrustdesigns.ufood;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;

public class Results extends ListActivity {

    ListView listView1;

    enum Category {
        Chicken, Beef, Chinese, Cocktails, Curry, Deserts, Fish, ForOne {
            public String toString() {
                return "For One";
            }
        },
        Lamb, LightBites {
            public String toString() {
                return "Light Bites";
            }
        },
        Pasta, Pork, Vegetarian
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.definition_main);

        listView1 = (ListView) findViewById(android.R.id.list);

        Bundle data = getIntent().getExtras();
        String category = data.getString("category");

        Category cat = Category.valueOf(category);

        String value = null;

        switch (cat) {
        case Chicken:
            value = "Chicken";
            break;
        case Beef:
            value = "Beef";
            break;
        case Chinese:
            value = "Chinese";
            break;
        case Cocktails:
            value = "Cocktails";
            break;
        case Curry:
            value = "Curry";
            break;
        case Deserts:
            value = "Deserts";
            break;
        case Fish:
            value = "Fish";
            break;
        case ForOne:
            value = "ForOne";
            break;
        case Lamb:
            value = "Lamb";
            break;
        case LightBites:
            value = "LightBites";
            break;
        case Pasta:
            value = "Pasta";
            break;
        case Pork:
            value = "Pork";
            break;
        case Vegetarian:
            value = "Vegetarian";
        }

        ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();

        nvp.add(new BasicNameValuePair("request", "category"));

        nvp.add(new BasicNameValuePair("cat", value));

        ArrayList<JSONObject> jsondefs = Request.fetchData(this, nvp);

        String[] defs = new String[jsondefs.size()];

        for (int i = 0; i < jsondefs.size(); i++) {
            try {
                defs[i] = jsondefs.get(i).getString("Name");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        uFoodAdapter adapter = new uFoodAdapter(this, R.layout.definition_list,
                defs);
        listView1.setAdapter(adapter);

    }

}
  • 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-01T15:52:39+00:00Added an answer on June 1, 2026 at 3:52 pm

    Basically I changed the way it was retrieving the data to send by using the position parameter of the onitemclick to get the item from the array being used to populate the listview.

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

Sidebar

Related Questions

I'm having a problem with getting this code to print out to file due
I am having problem getting this piece of code to run. The class is
I'm having a problem getting this test case to work. Can anyone point me
I am having a problem getting a list of fields from a query defined
I'm having troubles getting this to work. Basically I have a python program that
I'm having a real difficult time getting this code to work. I'm trying to
I have the following code, however im having a problem getting window.location to work
I'm having some trouble getting this layout to work correctly in IE. The problem
I'm having a problem getting this functionality to work. Situation is: User Drags an
I am having problem getting my tooltip to work when using the jQuery load()

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.