我正在尝试编写一个简单的java程序来模拟掷骰子。我想我的一切都是正确的,除了我无法弄清楚的错误。我搜索了这个网站并尝试了一些给别人的答案都无济于事。
到目前为止尝试:卸载/重新安装Eclipse,
添加import javax.swing.JComponent
import java.util.Random;
import javax.swing.JOptionPane;
public class Randomnum {
public int[] math(int[]sum, int number1){
Random randomnumbers = new Random();
int a, b;
for (a=0;a<number1;a++){
int dice1 = 1 + randomnumbers.nextInt(6);
int dice2 = 1 + randomnumbers.nextInt(1);
b = dice1 + dice2;
sum[a]=b;
}
return sum;
}
public static void main(String[]args){
String RollNumber;
RollNumber =
JOptionPane.showInputDialog("Roll the Dice ");
int number1;
number1 = Integer.parseInt(RollNumber);
int sum[]=new int [number1];
int []arr = math(sum[],number1);
JOptionPane.showMessageDialog(null, "The sum of each roll " +arr+ "number of roll "+number1 + "","Results" JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
private static int[] math(int i, int number1) {
return null;
}
}
这是我收到的错误:
&#34;无法解析javax.swing.JComponent类型。它是从所需的.class文件&#34;
间接引用的