将值设置为从上一个活动传递的Textview时出现NullPointerException

时间:2014-07-31 11:16:07

标签: android android-intent textview

Intent i = getIntent();
categorie_label = i.getStringExtra("categorie_label");
TextView txtrank = (TextView) findViewById(R.id.catid);
txtrank.setText(categorie_label);

为什么以下代码返回NullPointerException?请帮忙

1 个答案:

答案 0 :(得分:0)

您的活动可能在布局中找不到具有指定ID的TextView,因此它为null。您应该检查它是否包含在该布局中。