0

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

"

適切な2行があります

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 が正しく実行されていないことがわかりました。すみません、紛らわしかったのかな.. ><

4

2 に答える 2

1

それは私にとってはうまくいきます。この方法でjarを実行していることを確認してください

java -jar addit.jar

入力

1 2

編集:(addit.exeでこれを試してください)

Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the first digit: ");
x = scanner.nextInt();

scanner.nextLine(); // skips '\n' causing the problem

System.out.println("Please enter the second digit: ");
y = scanner.nextInt();

z = x + y;
于 2013-06-28T19:13:12.957 に答える