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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:40:28+00:00 2026-05-28T06:40:28+00:00

I’m trying to build a contact application In the main activity i Show a

  • 0

I’m trying to build a contact application

In the main activity i Show a list of all the contacts.

However, when I try to launch an activity after an item from
the list has been clicked, I get Error:

FATAL EXCEPTION: main 01-20 09:54:48.407: E/AndroidRuntime(8459):
java.lang.IllegalStateException: this should only be called when the
cursor is valid

It seems that somehow the adapter methods (getView, getCount) keep calling

My Code is as follows,

public void onCreate(Bundle icicle)
{
    super.onCreate(icicle);

    setContentView(R.layout.main);

    initComponents();

    final String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, sortOrder);

    startManagingCursor(c);

    final MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(mContext, c);

    list.setAdapter(adapter);

    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
             Intent intent  = new Intent (mContext, SingleContact.class);
                         startActivity(intent);
        }
    });

}

/**
 * An adapter which handle the contacts
 * 
 * @author intel
 * 
 */
public class MySimpleArrayAdapter extends CursorAdapter
{
    private LayoutInflater mInflater;
    private Cursor cur;

    public MySimpleArrayAdapter(Context context, Cursor c)
    {
        super(context, c);
        this.mInflater = LayoutInflater.from(context);
        this.cur = c;
    }

    public MySimpleArrayAdapter(Context context, Cursor c, boolean a)
    {
        super(context, c, a);
        this.mInflater = LayoutInflater.from(context);
        this.cur = c;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor)
    {
        TextView tvName = null;

        tvName = (TextView) view.findViewById(R.id.contact_item_text_view_name);

        tvName.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent)
    {
        TextView tvName = null;

        ImageView ivPhoto;

        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View convertView = mInflater.inflate(R.layout.contact_item, parent, false);

        tvName = (TextView) convertView.findViewById(R.id.contact_item_text_view_name);

        tvName.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

        return convertView;
    }


    @Override
    public int getCount()
    {
        Thread.dumpStack();

        return cur.getCount();
    }

}

Here’s the log:

01-20 09:54:48.407: E/AndroidRuntime(8459): FATAL EXCEPTION: main
01-20 09:54:48.407: E/AndroidRuntime(8459): java.lang.IllegalStateException: this should only be called when the cursor is valid
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.CursorAdapter.getView(CursorAdapter.java:175)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.AbsListView.obtainView(AbsListView.java:1409)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.ListView.measureHeightOfChildren(ListView.java:1307)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.ListView.onMeasure(ListView.java:1127)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.View.measure(View.java:8510)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:566)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.View.measure(View.java:8510)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.View.measure(View.java:8510)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3202)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.View.measure(View.java:8510)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3202)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.View.measure(View.java:8510)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.ViewRoot.performTraversals(ViewRoot.java:871)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.view.ViewRoot.handleMessage(ViewRoot.java:1921)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.os.Looper.loop(Looper.java:143)
01-20 09:54:48.407: E/AndroidRuntime(8459): at android.app.ActivityThread.main(ActivityThread.java:4196)
01-20 09:54:48.407: E/AndroidRuntime(8459): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 09:54:48.407: E/AndroidRuntime(8459): at java.lang.reflect.Method.invoke(Method.java:507)
01-20 09:54:48.407: E/AndroidRuntime(8459): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-20 09:54:48.407: E/AndroidRuntime(8459): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-20 09:54:48.407: E/AndroidRuntime(8459): at dalvik.system.NativeStart.main(Native Method)

Please help me regarding this.

  • 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-05-28T06:40:29+00:00Added an answer on May 28, 2026 at 6:40 am

    But how can you say that error is coming from your pasted code…
    as your class “MySimpleArrayAdapter” is not involved in error logs.
    I do not think error is coming from your pasted code…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.