gpt4 book ai didi

java - 选择随机数以选择数组索引时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 03:08:49 25 4
gpt4 key购买 nike

<分区>

编辑: 已解决。这是一个愚蠢的错误!感谢您的快速回复。我有 6 个数组,每个数组有 150-200 个元素。现在,当我尝试选择索引号时,前两个选择得很好,但从第三个索引号开始,应用程序开始崩溃。应用只有一项 Activity 。

String A[]={};
String B[]={};
...
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void generate(View v) {
tToast("Insult on your beep!");
Gener();
}

public void Gener()
{

int i1 = new Random().nextInt(A.length);
String r1 = (A[i1]);

int i2 = new Random().nextInt(B.length);
String r2 = (A[i2]);

int i3 = new Random().nextInt(C.length);
String r3 = (A[i3]);

int i4 = new Random().nextInt(D.length);
String r4 = (A[i4]);

int i5 = new Random().nextInt(E.length);
String r5 = (A[i5]);

int i6 = new Random().nextInt(F.length);
String r6 = (A[i6]);

String fin = r1 + r2 +r3 + r4 +r5 +r6;
//Works OK up to r2 but from r3 error occurs
final TextView mTextView = (TextView) findViewById(R.id.Gen);
mTextView.setText(fin);
tToast("Me works");
}
private void tToast(String s) {
Context context = getApplicationContext();
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, s, duration);
toast.show();
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com