0

I have simple java code to select the file and return array.
When I use dedicated method (whole code below), my compilation (in IntelliJ) does not end -> it gets to the last lane of public static void main(String[] arg), it executes last lane System.out.println("Program ends."); but I don't get information from compilator:

Process finished with exit code -1


Instead I need to stop it manually and if I want to run it again I get information that I can't run the code in parallel, would I like to stop it and rerun now.

Whole code:
import java.util.HashMap;               //import the HashMap class
import java.io.File;                    // Import the File class
import java.io.FileNotFoundException;   // Import this class to handle errors
import java.util.Scanner;               // Import the Scanner class to read text files
import java.awt.FileDialog;            
import java.awt.Frame;                 

public class Project1
{
    public static void main(String[] arg)
    {
        HashMap<Integer, int[][]> dicUsedFuncs = new HashMap<Integer, int[][]>();
        //import textfile with haskell code
        String[] arrString=SelectFile();
        System.out.println(arrString[0]);
        System.out.println(arrString[1]); 
        //scan load
        System.out.println("End");
    }
    private static String[] SelectFile()
    {
        String[] arrReturn = new String[2];
        String strDefaultPath=System.getProperty("user.dir");   //default location to open
        Frame frame = null;
        FileDialog fd = new FileDialog(frame, "Please choose a text file with code.", FileDialog.LOAD);
        fd.setDirectory(strDefaultPath);
        fd.setFile("*.txt");
        fd.setVisible(true);
        String filename = fd.getFile();                           //get just the selected file name
        if (filename == null) {
            arrReturn[0] = "NotSelected";
        }else {
            filename= new File(fd.getFile()).getAbsolutePath();  //get full file path of selected file
            arrReturn[0] = "Selected";
            arrReturn[1] = filename;
        }

        return arrReturn;
    }
}
Hronic
  • 155
  • 1
  • 1
  • 7
  • Do you have problem in compiling the source code or is the problem running the application? Please [edit] your question to include the full source code you have (as a [mcve] if possible). Then add the complete error message you get to your question. – Progman May 22 '21 at 11:08
  • I updated the code - now there is everything. – Hronic May 22 '21 at 21:20
  • 1
    You have to dispose your GUI components, see https://stackoverflow.com/questions/6417358/awt-eventqueue-thread-and-awt-shutdown-thread-not-shutting-down – Progman May 22 '21 at 21:36

1 Answers1

0

I added following:

  • library
    import java.awt.Window;

  • loop to close all windows in method private static String[] SelectFile()
    for (Window window : Window.getWindows()) { window.dispose(); }

Hronic
  • 155
  • 1
  • 1
  • 7