亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android studio中兩個數字相加的錯誤結果

Android studio中兩個數字相加的錯誤結果

慕妹3146593 2021-06-07 17:42:48
我正在為 Android 用戶開發一個大腦訓練器應用程序。問題是有時當我嘗試將兩個數字相加時得到錯誤的結果(例如:問題是 2 + 2,當我按下按鈕并顯示結果是錯誤的。)但它是隨機發生的。感謝有人可以幫助我糾正方法。謝謝。這是 MainActivity.javaimport android.os.CountDownTimer;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.RelativeLayout;import android.widget.TextView;import java.util.ArrayList;import java.util.Random;public class MainActivity extends AppCompatActivity{    Button button, button1, button2, button3, button4, button5;    RelativeLayout relativeLayout;    TextView sumTextView, resultTextView, pointTextView, timerTextView;    ArrayList<Integer> answers=new ArrayList<Integer>();    int locOfCorrectAns, score=0, noOfQues=0;    public void playAgain(View view) {        score=0;        noOfQues=0;        pointTextView.setText("0/0");        resultTextView.setText("");        timerTextView.setText("30s");        button5.setVisibility(View.INVISIBLE);                          generateQues();        new CountDownTimer(30100, 1000){            @Override            public void onTick(long l){                timerTextView.setText(String.valueOf(l/1000)+"s");            }            @Override            public void onFinish(){                button5.setVisibility(View.VISIBLE);                timerTextView.setText("0s");                resultTextView.setText(Integer.toString(score)+"/"+Integer.toString(noOfQues));            }        }.start();    }    public void generateQues(){        Random random=new Random();        int a=random.nextInt(21);        int b=random.nextInt(21);        sumTextView.setText(Integer.toString(a)+"+"+Integer.toString(b));                     locOfCorrectAns=random.nextInt(4);            answers.clear();                    int incorrectAns;}
查看完整描述

1 回答

?
呼如林

TA貢獻1798條經驗 獲得超3個贊

tag為按鈕設置了錯誤的s。標簽應該是0to 3for button1to button4。


查看完整回答
反對 回復 2021-06-10
  • 1 回答
  • 0 關注
  • 272 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號