I am having a sort of odd problem. So I use BlueJ as my code editor, and it runs my code just fine. When I create a jar file and run it, the program throws the "Exception in "main" java.util.NoSuchElementException: No Line found".
I sort of have 2 questions here:
Why does my code run just fine in BlueJ but not other runtime environments or editors such as Visual Studio Code?
Also why is it failing at all?
Just so everyone is aware, I condensed the code and cut a few parts out. The issue still stands.
import java.util.*;
import java.util.Scanner;
import java.io.*;
/**
* Write a description of class mainBody here.
*
* @author (Brayden Anderson)
* @version (a version number or a date)
*/
public class mainBody{
public static ArrayList<String> Messages = new ArrayList<String>();
public static ArrayList<String> changeLog = new ArrayList<String>();
/**
* mainBody Constructor
* Setup Menu
*/
public mainBody(){
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to Solar!");
System.out.println("========================================");
System.out.println("1. Start Setup");
System.out.println("2. Quit Program");
System.out.println("Console: ");
System.out.println("[System]: Please Start Setup to Proceed");
String selection = scan.nextLine();
scan.close();
if(selection.equals("1")){
System.out.println("Starting Setup");
}else if(selection.equals("2")){
System.exit(1);
}else{
new mainBody();
}
}
/**
* Method main
*
* @param args A parameter
*/
public static void main(String[] args) {
new mainBody();
}
}
output in powershell/CMD:
Welcome to Solar!
- Start Setup
- Quit Program
Console: [System]: Please Start Setup to Proceed 1 <--User inputed [System]: Starting Setup!... [System]: Would you like to use drive " C " for Installation [System]: Y/N? [Warning]: Setup Halted, Awaiting User Response Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at Setup.autoSearchForDir(Setup.java:309) at Setup.startSetup(Setup.java:24) at mainBody.(mainBody.java:32) at mainBody.main(mainBody.java:489) PS C:\Users\brayd\desktop>
output in Bluej:
Welcome to Solar!
- Start Setup
- Quit Program Console: [System]: Please Start Setup to Proceed 1 <-- User input [System]: Starting Setup!... [System]: Would you like to use drive " C " for Installation [System]: Y/N? [Warning]: Setup Halted, Awaiting User Response [USER]: [Warning]: Setup Resumed [System ERROR]: Invalid Option, Restarting Setup... [System]: Would you like to use drive " C " for Installation [System]: Y/N? [Warning]: Setup Halted, Awaiting User Response y [USER]: y [Warning]: Setup Resumed [System]: Please type out the Directory you would like to install System Files, You do not need to include the slashed "" [System]: EXAMPLE " \Users* User *\Documents " [System]: Type "Cancel" to cancel and start over, Type "Back" to remove last directory