android中的数组indexoutofbound在问答应用程序中 RadioGroup-rg; 单选按钮rb1、rb2、rb3、rb4; 按钮chk,下一步; TextView-que; 公共静态整数标记,正确,错误; int标志=0; 公共静态字符串[]问题={“11*11”、“2+5”、“19/1”}; 公共静态字符串[]ans={“121”、“7”、“19”}; 字符串[]opt={“22”、“131”、“121”、“1111”、“25”、“7”、“52”、“70”、“19”、“1”、“不可能”、“0”}; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_-question); que=(TextView)findViewById(R.id.textView1); chk=(按钮)findViewById(R.id.button1); next=(按钮)findViewById(R.id.button2); rb1=(单选按钮)findViewById(R.id.rb1); rb2=(单选按钮)findViewById(R.id.rb2); rb3=(单选按钮)findViewById(R.id.rb3); rb4=(单选按钮)findViewById(R.id.rb4); rg=(放射组)findViewById(R.id.RadioGroup 1); setOnClickListener(新的OnClickListener(){ @凌驾 公共void onClick(视图arg0){ //TODO自动生成的方法存根 RadioButton uans=(RadioButton)findViewById(rg.getCheckedRadioButtonId()); 字符串uansText=uans.getText().toString(); if(uansText.equals(ans[flag])) { 正确的++; } 其他的 { 错误++; } int len=que.length()-1; flag++; if(flag

android中的数组indexoutofbound在问答应用程序中 RadioGroup-rg; 单选按钮rb1、rb2、rb3、rb4; 按钮chk,下一步; TextView-que; 公共静态整数标记,正确,错误; int标志=0; 公共静态字符串[]问题={“11*11”、“2+5”、“19/1”}; 公共静态字符串[]ans={“121”、“7”、“19”}; 字符串[]opt={“22”、“131”、“121”、“1111”、“25”、“7”、“52”、“70”、“19”、“1”、“不可能”、“0”}; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_-question); que=(TextView)findViewById(R.id.textView1); chk=(按钮)findViewById(R.id.button1); next=(按钮)findViewById(R.id.button2); rb1=(单选按钮)findViewById(R.id.rb1); rb2=(单选按钮)findViewById(R.id.rb2); rb3=(单选按钮)findViewById(R.id.rb3); rb4=(单选按钮)findViewById(R.id.rb4); rg=(放射组)findViewById(R.id.RadioGroup 1); setOnClickListener(新的OnClickListener(){ @凌驾 公共void onClick(视图arg0){ //TODO自动生成的方法存根 RadioButton uans=(RadioButton)findViewById(rg.getCheckedRadioButtonId()); 字符串uansText=uans.getText().toString(); if(uansText.equals(ans[flag])) { 正确的++; } 其他的 { 错误++; } int len=que.length()-1; flag++; if(flag,android,Android,只需删除=从if条件中签名或用以下代码替换您的代码…希望这有帮助 RadioGroup rg; RadioButton rb1,rb2,rb3,rb4; Button chk,next; TextView que; public static int Marks,Correct,wrong; int flag = 0; public static String[] question={"11*11","2+5","19/1"}; public static String[] ans={"121"

只需删除=从if条件中签名或用以下代码替换您的代码…希望这有帮助

RadioGroup rg;
RadioButton rb1,rb2,rb3,rb4;
Button chk,next;
TextView que;
public static int Marks,Correct,wrong;
int flag = 0;
public static String[] question={"11*11","2+5","19/1"};
public static String[] ans={"121","7","19"};
String[] opt={"22","131","121","1111","25","7","52","70","19","1","not Possible","0"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_question);
    que=(TextView)findViewById(R.id.textView1);
    chk=(Button)findViewById(R.id.button1);
    next=(Button)findViewById(R.id.button2);
    rb1=(RadioButton)findViewById(R.id.rb1);
    rb2=(RadioButton)findViewById(R.id.rb2);
    rb3=(RadioButton)findViewById(R.id.rb3);
    rb4=(RadioButton)findViewById(R.id.rb4);
    rg=(RadioGroup)findViewById(R.id.radioGroup1);


next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            RadioButton uans =  (RadioButton)findViewById(rg.getCheckedRadioButtonId());
            String uansText = uans.getText().toString();

            if(uansText.equals(ans[flag]))
            {

                Correct++;
            }
            else
            {
                wrong++;
            }
            int len = que.length()-1;
            flag++;
        if(flag<=len)
        {
            que.setText(question[flag]);
            rb1.setText(opt[(flag*4)]);
            rb2.setText(opt[(flag*4)+1]);
            rb3.setText(opt[(flag*4)+2]);
            rb4.setText(opt[(flag*4)+3]);

        }
        else {

            Intent in = new Intent(getApplicationContext(), Result.class);
            startActivity(in);
        }



        }
    });
if(flag
//试试这个方法,希望这能帮助你。。。
放射组rg;
单选按钮rb1、rb2、rb3、rb4;
按钮chk,下一步;
TextView-que;
正确的,错误的;
int标志=0;
公共静态字符串[]问题={“11*11”、“2+5”、“19/1”};
公共静态字符串[]ans={“121”、“7”、“19”};
字符串[]opt={“22”、“131”、“121”、“1111”、“25”、“7”、“52”、“70”、“19”、“1”、“不可能”、“0”};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
que=(TextView)findViewById(R.id.que);
chk=(按钮)findviewbyd(R.id.chk);
next=(按钮)findViewById(R.id.next);
rb1=(单选按钮)findViewById(R.id.rb1);
rb2=(单选按钮)findViewById(R.id.rb2);
rb3=(单选按钮)findViewById(R.id.rb3);
rb4=(单选按钮)findViewById(R.id.rb4);
rg=(放射组)findViewById(R.id.rg);
问题[旗帜];
rb1.setText(opt[(flag*4)]);
rb2.setText(opt[(标志*4)+1]);
rb3.setText(opt[(标志*4)+2]);
rb4.setText(opt[(标志*4)+3]);
next.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
RadioButton uans=(RadioButton)findViewById(rg.getCheckedRadioButtonId());
字符串uansText=uans.getText().toString();
if(uansText.equals(ans[flag])){
正确的++;
}否则{
错误++;
}
int len=问题长度;
flag++;
如果(标志
发布日志…当您试图访问数组中不存在的值时,您将获得绑定异常的数组索引…例如:如果数组长度为3,但试图访问第4个…此时您将获得异常…
数组索引自动绑定
表示您正在尝试读取不在您的阵列选择日志使用ctrl+C复制…03-23 03:38:25.799:E/AndroidRuntime(2097):java.lang.ArrayIndexOutOfBoundsException:length=3;index=3一行是不够的,我们知道您得到了ArrayIndexOutOfBoundsException,在这里发布完整的日志…这将无法工作空指针异常,只有两个问题显示不显示最后一个java.lang.RuntimeException:无法启动活动组件信息{com.example.quizapp/com.example.quizapp.Result};java.lang.NullPointerException您的结果类有问题,请发布整个logcat,以便更好地了解结果类,但首先交叉检查您的结果类..公共类结果扩展活动{TextView tv;@Override protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_result);tv=(TextView)findViewById(R.id.textView1);tv.settText(“您的分数是:“+Question.Correct”);}结果类的代码可能有问题。正确的交叉检查此valuelength函数不包含“()”圆括号?字符串数组不包含圆括号,但字符串包含圆括号。我试图限定.length();这是文本视图的长度,而不是问号。length我的错误嗯,最后你知道你的错误。@radhe12,如果我的ans对你有用,请你批准
if(flag<len)
        {
            que.setText(question[flag]);
            rb1.setText(opt[(flag*4)]);
            rb2.setText(opt[(flag*4)+1]);
            rb3.setText(opt[(flag*4)+2]);
            rb4.setText(opt[(flag*4)+3]);

        }
        else {

            Intent in = new Intent(getApplicationContext(), Result.class);
            startActivity(in);
        }
// try this way,hope this will help you...

    RadioGroup rg;
    RadioButton rb1, rb2, rb3, rb4;
    Button chk, next;
    TextView que;
    public int Correct, wrong;
    int flag = 0;
    public static String[] question = {"11*11", "2+5", "19/1"};
    public static String[] ans = {"121", "7", "19"};
    String[] opt = {"22", "131", "121", "1111", "25", "7", "52", "70", "19", "1", "not Possible", "0"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        que = (TextView) findViewById(R.id.que);
        chk = (Button) findViewById(R.id.chk);
        next = (Button) findViewById(R.id.next);
        rb1 = (RadioButton) findViewById(R.id.rb1);
        rb2 = (RadioButton) findViewById(R.id.rb2);
        rb3 = (RadioButton) findViewById(R.id.rb3);
        rb4 = (RadioButton) findViewById(R.id.rb4);
        rg = (RadioGroup) findViewById(R.id.rg);

        que.setText(question[flag]);
        rb1.setText(opt[(flag * 4)]);
        rb2.setText(opt[(flag * 4) + 1]);
        rb3.setText(opt[(flag * 4) + 2]);
        rb4.setText(opt[(flag * 4) + 3]);

        next.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
                String uansText = uans.getText().toString();
                if (uansText.equals(ans[flag])) {
                    Correct++;
                } else {
                    wrong++;
                }
                int len = question.length;
                flag++;
                if (flag < len) {
                    que.setText(question[flag]);
                    rb1.setText(opt[(flag * 4)]);
                    rb2.setText(opt[(flag * 4) + 1]);
                    rb3.setText(opt[(flag * 4) + 2]);
                    rb4.setText(opt[(flag * 4) + 3]);

                } else {
                  Intent in = new Intent(getApplicationContext(), Result.class);
                  startActivity(in);
                }


            }
        });

        chk.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
                String uansText = uans.getText().toString();
                if (uansText.equals(ans[flag])) {
                    Toast.makeText(MainActivity.this,"Your Ans Is Correct",Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this,"Your Ans Is Wrong",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }