简体   繁体   English

对象无法解析或不是字段

[英]object cannot be resolved or is not a field

I'm a newbie in java and while i'm doing coding for the sitting plan the counsole kept giving me errors Please help >.< 我是Java的新手,而我正在为座位计划进行编码时,counsole不断给我带来错误,请帮助>。<

This is the class for SittingPlan 这是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;
}

and this is the stacktrace 这是堆栈跟踪

Exception in thread "main" java.lang.Error: Unresolved compilation problem: shuffle cannot be resolved or is not a field 线程“主”中的异常java.lang.Error:未解决的编译问题:随机播放无法解决或不是字段

at SittingPlan.shuffle(SittingPlan.java:22)
at mainlaunch.main(mainlaunch.java:6)

This line is wrong: 这行是错误的:

SittingPlan.shuffle.setName();

shuffle() is a method, but it's not static . shuffle()是一种方法,但不是static It returns void , so you can't call setName() on the return value. 它返回void ,所以您不能在返回值上调用setName()

I can't guess what you want. 我猜不到你想要什么。 This code is confusing. 这段代码令人困惑。

I think a better idea would be using Java collections, like this: 我认为一个更好的主意是使用Java集合,例如:

List<Student> classList = new ArrayList<Student>();
// populate with Student instances
Random random = new Random(seed);
Collections.shuffle(classList, random);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM