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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:18:22+00:00 2026-06-14T08:18:22+00:00

I’m not used to this adapters thing and I’m having a problem with a

  • 0

I’m not used to this adapters thing and I’m having a problem with a CursorAdaptor. Here’s my classes:

public class TicketsAdapter extends CursorAdapter {
    private Cursor cursor;
    private Context context;
    private final LayoutInflater inflater;

    public TicketsAdapter (Context context, Cursor cursor) {
        super(context, cursor, FLAG_REGISTER_CONTENT_OBSERVER);
        this.cursor = cursor;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void bindView(View view, Context context, Cursor cursor) {
        //cursor.moveToFirst();     I have tried this, same error   
        //try {    I have used this 'try' and find out here's the code where an exception is being throwed
        TextView ticketId = (TextView) view.findViewById(R.id.ticketId);
        TextView ticketCourse = (TextView) view.findViewById(R.id.ticketCourse);
        TextView ticketDate = (TextView) view.findViewById(R.id.ticketDate);
        TextView ticketTime = (TextView) view.findViewById(R.id.ticketTime);
        RelativeLayout row = (RelativeLayout) view.findViewById(R.id.ticketRow);
        TextView jogodaveia = (TextView) view.findViewById(R.id.textView1);

        ticketId.setText(cursor.getString(cursor.getColumnIndex("ticket_id")));
        ticketCourse.setText(cursor.getString(cursor.getColumnIndex("course")));
        ticketDate.setText(cursor.getString(cursor.getColumnIndex("date")));
        ticketTime.setText(cursor.getString(cursor.getColumnIndex("departure")));

        String present = cursor.getString(cursor.getColumnIndex("present"));

        if (present.equals("0")) {
            row.setBackgroundColor(Color.rgb(210, 245, 210));
            jogodaveia.setTextColor(Color.rgb(16, 181, 4));
        } else {
            row.setBackgroundColor(Color.rgb(255, 255, 255));
            jogodaveia.setTextColor(Color.rgb(206, 109, 0));
        }
        //} catch (Exception e) {android.util.Log.w("ADAPTER", e.toString());}
    }

    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final View view = inflater.inflate(R.layout.ticket,parent,false); 
        return view;
    }
}

And in my Tickets.java I have:

public class Tickets extends ListActivity {
    private SQLiteDatabase db=null;
    private Cursor cursor=null;
    private ListView layout;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tickets);

        layout = getListView();
        layout.setDividerHeight(3);

        db = (new DatabaseHelper(this)).getWritableDatabase();
        cursor = db.rawQuery("SELECT _id, ticket_id, course, date, departure FROM tickets ORDER BY date",
                                                            null);
        //cursor.moveToFirst();   I have tried this here too
        layout.setAdapter(new TicketsAdapter (Tickets.this, cursor));

    }
    ....
}

The error I get is

Failed to read row 0, column -1 from a CursorWindow which has 5 rows, 5 columns.
11-15 00:03:30.700: W/ADAPTER(1756): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

BUT, still my list is shown, but does not works fine. Any ideas of what I’m doing wrong?

  • 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-14T08:18:23+00:00Added an answer on June 14, 2026 at 8:18 am
    Failed to read row 0, column -1
    

    This means that one of your columns was not found, the row index is fine.


    Here you ask for "present":

    String present = cursor.getString(cursor.getColumnIndex("present"));
    

    But you forgot "present" in your query:

    cursor = db.rawQuery("SELECT _id, ticket_id, course, date, departure FROM tickets ORDER BY date", null);
    

    Also you should find all of your Views in newView() once and store them in a ViewHolder. The same is true for your column indices. There is no need to repeatedly search for the same information and this will give you a faster app.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.