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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:05:38+00:00 2026-06-08T17:05:38+00:00

i am creating an application that pulls bookings from my local server in JSON

  • 0

i am creating an application that pulls bookings from my local server in JSON and displays them in a ListView.

I managed to pull the data and display in a base List format, but decided create a better looking List. I have been following a guide from ezzylearning that adds more elements to the ListView.

I have checked the code and googled around, but I am still getting a error with the ListView in some form. Not sure how to solve or debug this problem.


Ignition.java (mainActivity) :

package com.systematix.sxConcept;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
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.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;


public class Ignition extends Activity {

    // url to make request
    private static String url = "http://10.0.0.103/android/data";

    public String company;
    public String course;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ignition);
        new ReadJSONFeedTask().execute(url);
    }

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

    public String readJSONFeed(String URL){
        StringBuilder stringBuilder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(URL);
        try{
            HttpResponse response = client.execute(httpget);
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if(statusCode == 200){
                HttpEntity entity = response.getEntity();
                InputStream content = entity.getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(content));
                String line;
                while ((line = reader.readLine()) != null){
                    stringBuilder.append(line);
                }
            }else{
                Log.e("JSON", "Failed to download list");
            }
        } catch (ClientProtocolException e){
            e.printStackTrace();
        } catch (IOException e){
            e.printStackTrace();
        }

        return stringBuilder.toString();
    }

    private class ReadJSONFeedTask extends AsyncTask<String, Void, String> {
        protected String doInBackground(String... urls){
            return readJSONFeed(urls[0]);
        }

        protected void onPostExecute(String result){
            try{
                JSONArray jsonArray = new JSONArray(result);
                Log.i("JSON", "Number of surveys in feed :" + jsonArray.length());
                ListView listView = (ListView) findViewById(R.id.listView1);

                /*String[] responseList;        
                responseList = new String[jsonArray.length()];*/

                Bookings[] booking_data;
                booking_data = new Bookings[jsonArray.length()];

                for (int i =0; i < jsonArray.length(); i++){
                    JSONObject jsonObject = jsonArray.getJSONObject(i);

                    booking_data[i] = new Bookings(jsonObject.getString("Company"),jsonObject.getString("CourseTitle"));

                    //responseList[i] = jsonObject.getString("bookdate") + " - " + jsonObject.getString("Company");
                }

                BookingsAdapter adapter = new BookingsAdapter(getBaseContext(),
                        R.layout.listview_item_row, booking_data); //export the data to a custom adapter

               /* View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
                listView.addHeaderView(header);*/

                listView.setAdapter(adapter);

                /*ArrayAdapter<String> newAdapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.test_list_item, responseList);
                listView.setAdapter(newAdapter);*/

            } catch (Exception e){
                e.printStackTrace();
            }
        }
    }

}

BookingsAdapter.java :

package com.systematix.sxConcept;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class BookingsAdapter extends ArrayAdapter<Bookings>{

    Context context;
    int layoutResourceId;   
    Bookings data[] = null;

    public BookingsAdapter(Context context, int layoutResourceId, Bookings[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            BookingHolder holder = null;

            if(row == null)
            {
                LayoutInflater inflater = ((Activity)context).getLayoutInflater();
                row = inflater.inflate(layoutResourceId, parent, false);

                holder = new BookingHolder();
                holder.company = (TextView)row.findViewById(R.id.rowCompany);
                holder.course = (TextView)row.findViewById(R.id.rowCourse);

                row.setTag(holder);
            }
            else
            {
                holder = (BookingHolder)row.getTag();
            }

            Bookings booking = data[position];
            holder.company.setText(booking.company);
            holder.course.setText(booking.course);

            return row;
        }

        static class BookingHolder
        {
            TextView company;
            TextView course;
        }
    }

Bookings.java :

package com.systematix.sxConcept;

public class Bookings {
    public String company;
    public String course;
    public Bookings(){
        super();
    }

    public Bookings(String company, String course) {
        super();
        this.company = company;
        this.course = course;
    }
}

The XML layout files are a copy of the 1’s seen in the tutorial, with the icon replaced as a Textview.


These are the errors:

07-24 12:36:10.154: E/AndroidRuntime(331): FATAL EXCEPTION: main
07-24 12:36:10.154: E/AndroidRuntime(331): java.lang.ClassCastException: android.app.ContextImpl
07-24 12:36:10.154: E/AndroidRuntime(331):  at com.systematix.sxConcept.BookingsAdapter.getView(BookingsAdapter.java:31)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.AbsListView.obtainView(AbsListView.java:1430)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.ListView.fillDown(ListView.java:670)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.ListView.fillFromTop(ListView.java:727)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.ListView.layoutChildren(ListView.java:1598)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.AbsListView.onLayout(AbsListView.java:1260)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.View.layout(View.java:7175)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.View.layout(View.java:7175)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.View.layout(View.java:7175)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.View.layout(View.java:7175)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.View.layout(View.java:7175)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.os.Looper.loop(Looper.java:123)
07-24 12:36:10.154: E/AndroidRuntime(331):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-24 12:36:10.154: E/AndroidRuntime(331):  at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:36:10.154: E/AndroidRuntime(331):  at java.lang.reflect.Method.invoke(Method.java:507)
07-24 12:36:10.154: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-24 12:36:10.154: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-24 12:36:10.154: E/AndroidRuntime(331):  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-06-08T17:05:42+00:00Added an answer on June 8, 2026 at 5:05 pm

    try this

    BookingsAdapter adapter = new BookingsAdapter(Ignition.this,
                        R.layout.listview_item_row, booking_data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating application that simply reads data from an XML file and displays
I'm creating an application that will store geolocation data for specific transactions. Should I
I am creating an application that requires a single row of data to be
I have been working on creating an application that sends a string from an
I'm creating an application that basically downloads and uploads files from various types of
Im creating application that will display remote page on the UIWebView using local images
I'm creating an application that will use a lot of data which is, for
I am working on a backend Grails application that pulls information periodically from a
I have developed an application that pulls X amount of records from my database
I'm creating an application that allows the user to store information about their classes.

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.