/ / NullPointerException при спробі setText - android, textview, android-arrayadapter, getview

NullPointerException при спробі setText - android, textview, android-arrayadapter, getview

TextView повинен бути введений, я не знаю, чому він говорить NullPointerException на textView.setText ("тест");

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;
}

Відповіді:

0 для відповіді № 1

Спробуйте:

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

Використовуйте findViewById , щоб отримати перегляд.