0

我有以下代码:

public class P1R1 extends Activity {

    int correctCounter;
    private String[] answerString;
    private TextView score;
    private static final Random rgenerator = new Random();
    protected static final String EXTRA_playerOneScore = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.level);

        score = (TextView) findViewById(R.id.score);

        correctCounter = 0;

        loadActivity();
        //start round timer
        new CountDownTimer(60000, 1000) {

            final TextView timer = (TextView) findViewById(R.id.timer);


            public void onTick(long millisUntilFinished) {
                timer.setText("Time: " + millisUntilFinished / 1000 + "s");
            }

            public void onFinish() {
                Intent roundOneToTwo = new Intent(getActivity(), R1R2.class);
                String playerOneScore = String.valueOf(correctCounter);
                roundOneToTwo.putExtra(EXTRA_playerOneScore, playerOneScore);
                startActivity(roundOneToTwo);
            }
         }.start();

我有一个计时器正在运行,当计时器结束时,我希望它Intent运行,但我的 Intent 语句出现错误The constructor Intent(new CountDownTimer(){}, Class<R1R2>) is undefined

我确实创建了一个 R1R2 类,但我的 Intent 仍然出错。我还是android的新手,所以如果你能提供帮助那就太好了。谢谢!

4

1 回答 1

0

代替

Intent roundOneToTwo = new Intent(this, R1R2.class);

尝试

Intent roundOneToTwo = new Intent(P1R1.this, R1R2.class);

Intent 构造函数的第一个参数应该是 Context,但您传递的是对 CountDownTimer 的引用。见http://developer.android.com/reference/android/content/Intent.html

于 2013-04-23T02:29:05.110 回答