我不参加下一个活动吗?

时间:2019-06-21 08:28:15

标签: android android-intent

我在该项目中遇到了太多问题,我没有打算使用这些数据,完成后,数据将转到HomeActivity,而不是DoneActivity

详细信息活动:

Intent intent = new Intent(this,DoneActivity.class);
Bundle dataSend = new Bundle();
dataSend.putInt("SCORE",score);
dataSend.putInt("TOTAL",totalQuestion);
dataSend.putInt("CORRECT",correctAnswer);
intent.putExtras(dataSend);
startActivity(intent);
finish();

DoneActivity:

Bundle extra = getIntent().getExtras();
if (extra != null){
    int score = extra.getInt("SCORE");
    int totalQuestion = extra.getInt("TOTAL");
    int correctAnswer = extra.getInt("CORRECT");

    txt_score.setText(String.format("SCORE : %d",score));
    txt_get_question.setText(String.format("PASSED : %d / %d",correctAnswer,totalQuestion));

如何处理这些数据?

这是错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

确保同时初始化两个文本视图

  

TextView txt_score = findViewById(R.id. id_of_txt_score );

     

TextView txt_get_question = findViewById(R.id. id_of_txt_get_question );

<Select />

因为在第56行处出现空指针异常。

您查看的方法未正确初始化。