bt.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
try{
List<Integer> dataList = new ArrayList<Integer>();
int start = 5;
int end = 15;
for (int i = start; i <= end; i++){
dataList.add(i);
}
Collections.shuffle(dataList);
int[] num = new int[dataList.size()];
for (int i = 0; i < dataList.size(); i++) {
num[i] = dataList.get(i);
}
for (int i = 0; i < num.length; i++) {
t.setText(num[i]);
}
}catch (Exception e) {
e.printStackTrace();
}
}});
我想告诉我的文本视图的随机数,但它没有显示或崩溃不捕获异常
I want to show my random number on text view but it shown nothing or crash without catch Exception
我应该怎么办?
什么,在哪里是我的错误?
What and where is my error?
您应该能够使用钻石操作符&LT;&GT;
。你只能显示一个字符串
的时间,所以先做个字符串
(你不需要复制到一个数组第一个)。喜欢的东西,
You should be able to use the diamond operator <>
. You can only display one String
at a time, so first make a String
(and you don't need to copy to an array first). Something like,
try {
List<Integer> dataList = new ArrayList<>(); // <-- <Integer> if you can't.
int start = 5;
int end = 15;
for (int i = start; i <= end; i++) {
dataList.add(i);
}
Collections.shuffle(dataList);
t.setText(dataList.toString());
} catch (Exception e) {
e.printStackTrace();
}