-3

this is an new question in reference this this post: Nullpointer on sql query with android

Quick History: - Main.Class - Main_fragment.Class

in Fragment this code:

    private void showList() {
    ArrayList<ContactListItems> contactList = new ArrayList<ContactListItems>();
    contactList.clear();

    String query = "SELECT * FROM "+SqlDbHelper.DATABASE_TABLE;
    Cursor c1 = sqlHandler.selectQuery(query);
    if (c1 != null && c1.getCount() != 0) {
        if (c1.moveToFirst()) {
            do {
                ContactListItems contactListItems = new ContactListItems();

                contactListItems.setID(c1.getString(c1.getColumnIndex("id")));

                contactListItems.setFirstName(c1.getString(c1.getColumnIndex("first name")));

                contactListItems.setSecondName(c1.getString(c1.getColumnIndex("secondname")));

                contactListItems.setBDAY(c1.getString(c1.getColumnIndex("bday")));


                contactList.add(contactListItems);

            } while (c1.moveToNext());
        }
    }
    c1.close();


    ContactListAdapter contactListAdapter = new ContactListAdapter(getActivity(), contactList);
    lvCustomList.setAdapter(contactListAdapter);

}

on the last line i get an null pointer.

lvCustomList.setAdapter(contactListAdapter);

This is my ContactListAdapter.class:

public class ContactListAdapter extends BaseAdapter {

Context context;
ArrayList<ContactListItems> contactList;

public ContactListAdapter(Context context, ArrayList<ContactListItems> list) {
    this.context = context;
    contactList = list;
}

@Override
public int getCount() {

    return contactList.size();
}

@Override
public Object getItem(int position) {

    return contactList.get(position);
}

@Override
public long getItemId(int position) {

    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup arg2) {
    ContactListItems contactListItems = contactList.get(position);


    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.custom_listview_item, null);

    }

    TextView tvfirstname = (TextView) convertView.findViewById(R.id.txtViewFirstNamee);
    tvName.setText(contactListItems.getFirstname());

    TextView tvsecondname = (TextView) convertView.findViewById(R.id.txtViewSecondName);
    tvPhone.setText(contactListItems.getSecondName());

    TextView tvbday = (TextView) convertView.findViewById(R.id.txtViewBDAY);
    tvbday.setText(contactListItems.getBDAY());

    return convertView;
}

Any ideas? :/

Community
  • 1
  • 1
Trombone0904
  • 4,132
  • 8
  • 51
  • 104

1 Answers1

1

lvCustomList is null....

If that isn't the case, post a log output and post the code where lvCustomList is initialized.

daemmie
  • 6,361
  • 3
  • 29
  • 45