2013-05-20 51 views
0
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?

回答

2

佈局應首先加載。你忘記撥打setContentView()

這就是爲什麼這些控件

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

回報null

+0

ahahhah謝謝!我正在爲這種愚蠢的疏忽而努力!非常感謝你=) – DomeWTF

相關問題