Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我无法在android Studio中解析equalsIgnoreCase_Java_Android - Fatal编程技术网

Java 我无法在android Studio中解析equalsIgnoreCase

Java 我无法在android Studio中解析equalsIgnoreCase,java,android,Java,Android,我是一个使用android studio开发android应用程序的新手。 我试图通过一些教程开发一个测验应用程序,但我遇到了一个无法解决equalsIgnoreCase的问题。 下面是我在JAVA类中使用的代码。请帮我指出我哪里做错了 public class QuizActivity extends AppCompatActivity implements View.OnClickListener { TextView tv; Button btnNext; RadioGroup rg;

我是一个使用android studio开发android应用程序的新手。 我试图通过一些教程开发一个测验应用程序,但我遇到了一个无法解决equalsIgnoreCase的问题。 下面是我在JAVA类中使用的代码。请帮我指出我哪里做错了

public class QuizActivity extends AppCompatActivity implements View.OnClickListener {

TextView tv;
Button btnNext;
RadioGroup rg;
RadioButton rb1,rb2,rb3,rb4;
String questions[]={"Pakistan found in?","Pakistan defence day?","First Governer General of Pakistan?"};
String answers[]={"1947","6 sep","Quid-i-Azam Muhammad Ali Jinnah"};
String choices[]={"1947","1946","1948","1945","7 sep","6 sep","8 sep","5 sep","Allama Muhammad Iqbal","Khan Liaqat Ali Khan","Quid-i-Azam Muhmmad Ali Jinnah","Tipu Sultan"};

int flag=0;
public static int marks,correct,wrong;

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

    tv=(TextView)findViewById(R.id.tvque);
    btnNext=(Button)findViewById(R.id.btnnext);
    rg=(RadioGroup)findViewById(R.id.radioGroup1);
    rb1=(RadioButton)findViewById(R.id.radio1);
    rb2=(RadioButton)findViewById(R.id.radio2);
    rb3=(RadioButton)findViewById(R.id.radio3);
    rb4=(RadioButton)findViewById(R.id.radio4);

    tv.setText(questions[flag]);
    rb1.setText(choices[0]);
    rb2.setText(choices[1]);
    rb3.setText(choices[2]);
    rb4.setText(choices[3]);

    btnNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public void onClick(View v) {
    RadioButton uanswers=(RadioButton)findViewById(rg.getCheckedRadioButtonId());
    String answerText=uanswers.getText().toString();
    if(uanswers.equalsIgnoreCase(answers[flag]));
    {
        correct++;
    }
    else
    {
        wrong++;
    }
    flag++;
    if(flag<questions.length) {
        tv.setText(questions[flag]);
        rb1.setText(choices[flag * 4]);
        rb2.setText(choices[flag * 4] + 1);
        rb3.setText(choices[flag * 4] + 2);
        rb4.setText(choices[flag * 4] + 3);
    }
    Intent in=new Intent(getApplicationContext(),ResultActivity.class);
    StartActivity(in);
}

}
公共类QuizaActivity扩展AppCompatActivity实现View.OnClickListener{
文本视图电视;
按钮btnNext;
放射组rg;
单选按钮rb1、rb2、rb3、rb4;
字符串问题[]={“巴基斯坦发现了吗?”,“巴基斯坦国防日?”,“巴基斯坦第一任总督?”};
字符串答案[]={“1947”、“9月6日”、“Quid-i-Azam Muhammad Ali Jinnah”};
字符串选择[]={“1947”、“1946”、“1948”、“1945”、“9月7日”、“9月6日”、“9月8日”、“9月5日”、“阿拉玛·穆罕默德·伊克巴尔”、“汗·利亚卡特·阿里·汗”、“魁迪·阿扎姆·穆罕默德·阿里·金纳”、“提普·苏丹”};
int标志=0;
公共静态整数标记,正确,错误;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u测验);
tv=(TextView)findviewbyd(R.id.tvque);
btnNext=(按钮)findViewById(R.id.btnNext);
rg=(放射组)findViewById(R.id.RadioGroup 1);
rb1=(RadioButton)findViewById(R.id.radio1);
rb2=(RadioButton)findViewById(R.id.radio2);
rb3=(RadioButton)findViewById(R.id.radio3);
rb4=(RadioButton)findViewById(R.id.radio4);
tv.setText(问题[标志]);
rb1.setText(选项[0]);
rb2.setText(选项[1]);
rb3.setText(选项[2]);
rb4.setText(选项[3]);
btnNext.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单菜单菜单主菜单);
返回true;
}
@凌驾
公共void onClick(视图v){
RadioButton uanswers=(RadioButton)findViewById(rg.getCheckedRadioButtonId());
字符串answerText=uanswers.getText().toString();
if(uanswers.equalsIgnoreCase(应答[标志]);
{
正确的++;
}
其他的
{
错误++;
}
flag++;

如果(通过查看代码标记,看起来像是打字错误,
equalsIgnoreCase
不适用于
单选按钮,但适用于
字符串

在这里,您的代码如下

RadioButton uanswers=(RadioButton)findViewById(rg.getCheckedRadioButtonId());
String answerText=uanswers.getText().toString();
if(uanswers.equalsIgnoreCase(answers[flag])){
    correct++;
}
但我认为,将答案与选定答案进行比较应该是这样的:

RadioButton uanswers=(RadioButton)findViewById(rg.getCheckedRadioButtonId());
String answerText=uanswers.getText().toString();
if(answerText.equalsIgnoreCase(answers[flag])){  // Use answerText instead of uanswers
    correct++;
}

但equalsIgnoreCase在android studio中仍然是红色的,它在建议选项中从来没有给我任何建议。我想我在设置或类似的东西上犯了一些愚蠢的错误。你删除了吗?”从if语句的末尾开始?我不这么认为。请查看我提供的代码,指出if语句,并建议我需要做什么。为什么在该语句的末尾添加“;”if(uanswers.equalsIgnoreCase(answers[flag]);