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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:34:00+00:00 2026-06-17T10:34:00+00:00

what’s my problem? I’m trying to create a custom adapter in the dialogue. I

  • 0

what’s my problem?
I’m trying to create a custom adapter in the dialogue. I can not understand what is the cause of the error.

create dialog:

  protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setTitle("Choose contact");

    view = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog, null);
    adb.setView(view);

    deditText = (EditText) view.findViewById(R.id.deditText);
    deditText.addTextChangedListener(this);
    dlvNames = (ListView) view.findViewById(R.id.dlvCheck);

    Cursor cursor = getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
            new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER },
            null, null, null);

      startManagingCursor(cursor);


     while (cursor.moveToNext()) {
         ID=i;
         CID=Long.valueOf(cursor.getString(0));
         NAME=cursor.getString(1);
         PHONE=cursor.getString(2);

         Contact_List.add(new Contact(ID,CID,NAME,PHONE));

      i++;
     }

    contactAdapter = new ContactAdapter(this,Contact_List );
    //crashes here
    dlvNames.setAdapter(contactAdapter);

    dialog = adb.create();
    return dialog;
}

create custom adapter:

    public class ContactAdapter extends ArrayAdapter<Contact> {

private final Activity context;
ArrayList<Contact> Contact_List;
LayoutInflater lInflater;


static class ViewHolder {
      public TextView tvName;
      public TextView tvPhone;

    }
public ContactAdapter(Activity context, ArrayList<Contact> Contact_List) {

    super(context, R.layout.item, Contact_List);
    this.context = context;
    this.Contact_List = Contact_List;
}

 public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;
    View view = convertView;

    if (view == null) {
        LayoutInflater inflater = context.getLayoutInflater();

      //view = lInflater.inflate(R.layout.item, parent, false);

        view = inflater.inflate(R.layout.item, null, true);

      holder = new ViewHolder();
      holder.tvName = (TextView) view.findViewById(R.id.tvName);
      holder.tvPhone = (TextView) view.findViewById(R.id.tvPhone);
      convertView.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    Contact c = getContact(position);

    holder.tvName.setText(c.name);
    holder.tvPhone.setText(c.phone);


    return view;
}
  Contact getContact(int position) {
        return ((Contact) getItem(position));
      }
}

LogCat:

    01-17 06:40:31.801: E/AndroidRuntime(1263): FATAL EXCEPTION: main
    01-17 06:40:31.801: E/AndroidRuntime(1263): java.lang.NullPointerException
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at com.example.testreadcontacts.ContactAdapter.getView(ContactAdapter.java:50)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.AbsListView.obtainView(AbsListView.java:2271)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.ListView.onMeasure(ListView.java:1156)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.View.measure(View.java:15172)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.Choreographer.doFrame(Choreographer.java:525)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.os.Handler.handleCallback(Handler.java:615)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.os.Handler.dispatchMessage(Handler.java:92)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.os.Looper.loop(Looper.java:137)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at android.app.ActivityThread.main(ActivityThread.java:4745)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at java.lang.reflect.Method.invokeNative(Native Method)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at java.lang.reflect.Method.invoke(Method.java:511)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    01-17 06:40:31.801: E/AndroidRuntime(1263):     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-17T10:34:02+00:00Added an answer on June 17, 2026 at 10:34 am
      convertView.setTag(holder);
    

    This is inside the block that checks for null. If you hit this line, that variable is garunteed to be null. You want it to be view.setTag instead.

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

Sidebar

Related Questions

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
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
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
I've tracked down a weird MySQL problem to the two different ways I was

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.