gpt4 book ai didi

java - 线程主错误中的异常

转载 作者:行者123 更新时间:2023-12-02 00:28:06 24 4
gpt4 key购买 nike

Possible Duplicate:
Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”'

我希望这只是一个简单的错误,我查找了许多其他人收到相同错误消息的实例,但他们的解决方案似乎都不适合我。我只是想知道你们是否可以帮我找到代码中的错误。我什至不确定它是否有效,因为我无法让它运行,所以我认为这可能是一个逻辑错误。

当我尝试运行以下冷程序时,我遇到了致命的异常错误。程序将会退出。

Eclipse 还给了我:java.lang.NoSuchMethodError:主要线程“main”中的异常

非常感谢您提供的任何帮助!

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;



public class JoPuzzle
{

public static Integer main(String[] args)
{
Scanner input = new Scanner(System.in);

System.out.println("Please enter the number of soliders");
int soldiers = input.nextInt();
System.out.println("Please enter the how many soldiers are skipped before the next death");
int count = input.nextInt();

List<Integer> soldiersList = new ArrayList<Integer>(soldiers);
for (int i = 1; i <= count; i++) {

soldiersList.add(i);

}



int currentIndex = 0;

while(soldiersList.size() > 1) {

currentIndex = (currentIndex - 1 + count) % soldiersList.size();

soldiersList.remove(currentIndex);

}

return soldiersList.get(0);

} //end main

}//end class

最佳答案

我们知道要执行任何java程序,我们应该有一个ma​​in函数。因为这是 JVM 可自调用的。并且函数的签名必须是..

public static void main(String[] args){
}

但是在你的代码中它看起来像这样......

public static Integer main(String[] args){
}

因此将其视为不同的函数,因此更改您的主要返回类型..

关于java - 线程主错误中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9662045/

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