-1

The textView shoud be instanced, I don't know why it says NullPointerException at textView.setText("test");

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

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.list_navdrawer, parent, false);

    TextView textView = (TextView) rowView.getTag(android.R.id.text1);
    textView.setText("test");

    if (position == mSelectedItem) {
        textView.setTextColor(getContext().getResources().getColor(android.R.color. holo_blue_dark));
        textView.setTypeface(Typeface.DEFAULT_BOLD);
    } else {
        textView.setTextColor(getContext().getResources().getColor(android.R.color.white));
    }

    return textView;
}
  • Use the debugger. It's null because the textview does not exist in the current layout or it's ID is not android.R.id.text1. Either way, the debugger will show you instantly. – Simon Nov 22 '14 at 23:59
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Simon Nov 22 '14 at 23:59
  • "android.R.id.text1" should be just "R.id.text1", no ? – Hacketo Nov 23 '14 at 00:24
  • are you using fragments? – SeahawksRdaBest Nov 23 '14 at 00:40

1 Answers1

0

Try:

TextView textView = (TextView) rowView.findViewById(android.R.id.text1); 

Use findViewById to get views.

asylume
  • 534
  • 3
  • 6