我是java的新手,虽然我正在为坐着的计划编码,但counsole一直给我错误 请帮助>。<
这是SittingPlan的课程
public SittingPlan()
{
String[] name = {"charles" };
String[] sex = {" Girl", "Boy"};
Students[] names = new Students[NUMBER_OF_STUDENTS];
currentStudents = 0;
for ( int count = 0; count < names.length; count++ )
names [ count ] = new Students ( name [count % 22 ], sex [ count / 22 ]);
}
public void shuffle()
{
currentStudents = 0;
SittingPlan.shuffle.setName();
for ( int first = 0; first < names.length; first++ )
{
int second = randomNumbers.nextInt ( NUMBER_OF_STUDENTS );
Students temp = names[ first ];
names[ first ] = names[ second ];
names[ second ] = (Students) temp;
}
}
public Students dealStudents()
{
if ( currentStudents < names.length )
return (Students) names[ currentStudents++ ];
else
return null;
}
这是堆栈跟踪
线程中的异常&#34; main&#34; java.lang.Error:未解决的编译问题: shuffle无法解析或不是字段
at SittingPlan.shuffle(SittingPlan.java:22)
at mainlaunch.main(mainlaunch.java:6)
答案 0 :(得分:0)
这一行错了:
SittingPlan.shuffle.setName();
shuffle()
是一种方法,但它不是static
。它返回void
,因此您无法在返回值上调用setName()
。
我猜不出你想要什么。这段代码令人困惑。
我认为更好的想法是使用Java集合,如下所示:
List<Student> classList = new ArrayList<Student>();
// populate with Student instances
Random random = new Random(seed);
Collections.shuffle(classList, random);