Java 比较两个不起作用的变量字符串

Java 比较两个不起作用的变量字符串,java,android-activity,Java,Android Activity,当我运行上述程序时,它似乎正确地获取了所有字符串。当我重复第一个问题时,如果答案正确,它会给我的分数加1,但每次迭代后,它都会认为答案是错误的,即使我知道答案是正确的 我输出我的答案和正确的答案,这样我就知道它们是匹配的 这是序列吗 编辑 正如有人建议的那样,我在比较之后设置了check var。我将其更改为以下内容,并且可以正常工作: public void onClick(View view) { String

当我运行上述程序时,它似乎正确地获取了所有字符串。当我重复第一个问题时,如果答案正确,它会给我的分数加1,但每次迭代后,它都会认为答案是错误的,即使我知道答案是正确的

我输出我的答案和正确的答案,这样我就知道它们是匹配的

这是序列吗

编辑

正如有人建议的那样,我在比较之后设置了check var。我将其更改为以下内容,并且可以正常工作:

            public void onClick(View view)
            {
                String answer = mEdit.getText().toString();
                questioncount++;


                if (answer.equals(check)) {
                    currentscore++;
                    //t3.setText("CORRECT");

                }
                else {
                    currentscore--;
                    //t3.setText("WRONG");
                };


                t4.setText(answer+" "+currentscore);
                t2.setText("Question "+questioncount+" of 20");

                final double randomnumber = Math.floor(Math.random()*(arraycount+1));
                t.setText(gcse_defs[(int) randomnumber]);
                String check = gcse_terms[(int) randomnumber];
                t3.setText(check);

            }

省略字符串,使其不是声明

在我看来,好像有两个变量叫做check。

你能更清楚地说明你的问题是什么吗?它是Java而不是JavascriptRichard,你是用记事本还是别的什么东西编码的?专业IDE将标记字符串检查=。。。行,并告诉您已经声明了一个局部变量,它隐藏了一个全局变量。你会立即注意到你即将犯一个错误。不知何故,这看起来更像JavaScript。
            public void onClick(View view)
            {
                String check = t3.getText().toString();
                String answer = mEdit.getText().toString();
                questioncount++;


                if (answer.equals(check)) {
                    currentscore++;
                    //t3.setText("CORRECT");

                }
                else {
                    currentscore--;
                    //t3.setText("WRONG");
                };


                t4.setText(answer+" "+currentscore);
                t2.setText("Question "+questioncount+" of 20");

                final double randomnumber = Math.floor(Math.random()*(arraycount+1));
                t.setText(gcse_defs[(int) randomnumber]);
                check = gcse_terms[(int) randomnumber];
                t3.setText(check);

            }
 public void onClick(View view){

    ...
     if (answer.equals(check)) {   // use a class member "check"

    ...
     String check = gcse_terms[(int) randomnumber];   // Declare use and display
     t3.setText(check);                             // local variable