2 sachinks SachinKS 于 2013.05.20 13:20 提问

调用onResume方法时报错
public class Scores extends Activity {

TextView tvPoints;
TextView tvRecord;

int record = 0;
int points = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    tvPoints = (TextView) findViewById(R.id.tvPoints);
    tvRecord = (TextView) findViewById(R.id.tvRecord);

    points = getIntent().getIntExtra("points", 0);
    record = getIntent().getIntExtra("record", 0);
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    tvPoints.setText("Points: "+points);
    tvRecord.setText("Record: "+record);
}
}

代码,在使用onResume方法时报出NullPointerException错误。

1个回答

baimy1985
baimy1985   2013.05.20 21:07

你的布局setContentView在哪加载的?如果只是没贴出来,那就去找tvPoints和tvRecord什么时候被置空了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!