我用java写了一个简单的加法程序,并把它做成了一个.exe文件。但是当我尝试运行 exe 文件时,即使从我的桌面上单击它,我也会收到错误“启动期间发生错误:”这个巨大的东西:
java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at addit.main(addit.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
at com.exe4j.runtime.WinLauncher.main(Unknown Source)
我的清单文件包含:
“主类:addit
"
它有正确的两行
addit.java 程序:
import java.util.Scanner;
public class addit
{
public static void main (String [] args)
{
int x;
int y;
int z;
System.out.println("Welcome to Addit!");
System.out.println("Please enter the first digit.");
Scanner scanner = new Scanner(System.in);
x = scanner.nextInt();
System.out.println("Please enter the second digit.");
y = scanner.nextInt();
z = x + y;
System.out.println("The sum of " + x + " and " + y + " is " + z);
}
}
另外,顺便说一句,程序编译并运行良好,即使通过 cmd 运行(当我运行 addit.java 时)。
编辑:哦,等等,对不起,原来 addit.exe 运行不正确。对不起,我一定是混淆了..><