0

我试图将整数值从一个活动放到第二个,但我得到了错误。不知道为什么会这样。由于此错误,第二个活动也无法启动。

这是第一个活动:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);
    mCount = (TextView) findViewById(R.id.mCount);
    init();
    if (Question.count(Question.class) != 35) { 
        fillDB();
    }

    shuffle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) { 
            random = new Random();
            int x = random.nextInt(34) + 1;
            questionnaire = Question.findById(Question.class, x);
            String q = questionnaire.getQuestion();
            question.setText(q); //

        }
    });

    new CountDownTimer(30000, 1000) { 
        public void onTick(long millisUntilFinished) {
            mCount.setText(
                    String.valueOf((int) (+millisUntilFinished / 1000)));
        }


        public void onFinish() {
            Intent intent = new Intent(Play.this, Score.class);
            **intent.putExtra("score", 13);**
            startActivity(intent);
        }
    }
            .start();
}

public void init() { 
    shuffle = (Button) findViewById(R.id.shuffle);
    question = (TextView) findViewById(R.id.question);
}

public void fillDB() { 
    for (int i = 0; i < 35; i++) {
        System.out.println(getResources().getStringArray(R.array.questions)[i]);
        questionnaire = new Question(getResources().getStringArray(R.array.questions)[i], i);
        Question.save(questionnaire);
    }
}

public void increaseInteger(View view) { 
    minteger = minteger + 1;
    display(minteger);
}

public void decreaseInteger(View view) { 
    minteger = minteger - 1;
    display(minteger);
}

private void display(int number) {
    score.setText("" + number);
}

第二个活动:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_score);
    bt = (Button) findViewById(R.id.bt);
    tv2 = (TextView) findViewById(R.id.tv2);
    tv3 = (TextView) findViewById(R.id.tv3);

    int score = getIntent().getExtras().getInt("score", 13); 
    bt.setText(String.valueOf(score));

    switch (score) { 
        case 1:
        case 2:
        case 3:
            tv3.setText(R.string.sc1);
            tv2.setText(R.string.l1);
            break;
        case 4:
        case 5:
            tv3.setText(R.string.sc2);
            tv2.setText(R.string.l1);
            break;
        case 6:
        case 7:
            tv3.setText(R.string.sc3);
            tv2.setText(R.string.l2);
            break;
        case 8:
        case 9:
            tv3.setText(R.string.sc4);
            tv2.setText(R.string.l2);
            break;
        case 10:
        case 11:
            tv3.setText(R.string.sc5);
            tv2.setText(R.string.l3);
            break;
        case 12:
        case 13:
            tv3.setText(R.string.sc6);
            tv2.setText(R.string.l3);
            break;
        case 14:
        case 15:
        case 16:
            tv3.setText(R.string.sc7);
            tv2.setText(R.string.l3);
            break;
        case 17:
        case 18:
            tv3.setText(R.string.sc8);
            tv2.setText(R.string.l4);
            break;
        case 19:
        case 20:
            tv3.setText(R.string.sc9);
            tv2.setText(R.string.l4);
            break;
        default:
            tv3.setText(R.string.sc10);
            tv2.setText(R.string.l5);

    }

    Button share = (Button) findViewById(R.id.share); 
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("text/plain");
                i.putExtra(Intent.EXTRA_SUBJECT, "What if?");
                String sAux = "\nLet me recommend you this application\n\n";
                sAux = sAux + "https://Play.google.com/store/apps/details?id=Orion.S.. \n\n";
                i.putExtra(Intent.EXTRA_TEXT, sAux);
                startActivity(Intent.createChooser(i, "choose one"));
            } catch (Exception e) { //e.toString();
            }

        }
    });

    Button exit = (Button) findViewById(R.id.exit); 
    exit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
            System.exit(0);
        }
    });
}

怎么了?)

4

0 回答 0