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

The Archive Base Latest Questions

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

I’m having an issue that I just can’t seem to trace down the cause

  • 0

I’m having an issue that I just can’t seem to trace down the cause of. This may be simply due to my lack of familiarity with loaders…

I have a custom adapter I use to set a prompt for a spinner in the “closed” position (single line display) until the first selection is made. I’ve used this before with great success, but this time it’s not working. The only difference is that now I’m using loaders.

When the adapter tries to access the cursor in my overridden getView method, the cursor is null and of course I get a force close with a null pointer exception. I don’t understand how the cursor can be null there as obviously the getDropDownView method (which I don’t override) has access to the cursor as the dropdown is populated…

All I can think is that for some reason the getView method is retaining the original null that is passed in as a placeholder while the loader does it’s work. I would think that when I use changeCursor that reference would change as well, but it seems that it isn’t.

main activity adapter call

adapter = new CursorAdapter_SpinnerPrompt(this,
    R.layout.rowlayout_black, null, new String[] { ThreadMillDB.THREADMILL_THREAD }, new int[] { R.id.ListItem });
mThreadChooser.setAdapter(adapter);

relevant loader code

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.changeCursor(cursor);
}

adapter code

public class CursorAdapter_SpinnerPrompt extends SimpleCursorAdapter {
    private Context context;
    private int layout;
    private Cursor c;
    private String[] from;
    private int[] to;
    public static boolean spinnerFlag = false;

    public CursorAdapter_SpinnerPrompt(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.context = context;
        this.layout = layout;
        this.c = c;
        this.from = from;
        this.to = to;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = View.inflate(context, layout, null);
        if (spinnerFlag != false) {
            c.moveToPosition(position);          // cursor is null here... why?  How to fix?
            TextView tv = (TextView) convertView;
            tv.setText(c.getString(c.getColumnIndex(ThreadMillDB.THREADMILL_THREAD)));
        } else {
            TextView tv = (TextView) convertView;
            tv.setText("Choose a thread");
            tv.setTextColor(Color.parseColor("#778899"));
        }
        return convertView;
    }
}

UPDATE

And of course in typing this out I figured out a solution. I moved the creation of the adapter out of my activity onCreate and into onLoadFinished and put the cursor into the call. However, this seems messier than the way I was trying to do it. Is there any modification I can make to my original methods (shown above) to make it work without having to move the adapter instantiation to the onLoadFinished 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-16T01:14:23+00:00Added an answer on June 16, 2026 at 1:14 am

    your suspicious is correct.

    The cursor reference you remembered on your constructor is not the same that you passed on chageCursor(Cursor c).
    The proper way to get the cursor on a CursorAdapter is calling getCursor() than you’ll get the reference to the cursor you passed on changeCursor(Cursor c).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.