HashMap我在 FX 程序的启动方法中暂时显示信息时遇到问题。public class stack extends Application{ String mCurrentLocation; // Store current location // Map to store name as keys and easting and northing as values HashMap<String, List <Double>> dict = new HashMap<>(); public static void main(String[] args) { stack mainObject = new stack(); mainObject.run();// Method where the program is built launch(args); } public void start(Stage primaryStage) throws Exception{ System.out.println("In in startFX: "); // debugging only System.out.println(dict); // debugging only // More fx code } private void run(){ System.out.println("In main"); System.out.println(dict); //Read Northing and Easting input received from a txt file try{ Scanner scanner = new Scanner(new File("NorthingAndEastings.txt")); while(scanner.hasNext()){ List<Double> coordinates = new ArrayList<>(); String name = scanner.next(); // key Double easting = scanner.nextDouble(); coordinates.add(easting); // list(0) Double northing = scanner.nextDouble(); coordinates.add(northing); //list(1) this.dict.put(name, coordinates); } scanner.close(); } catch(FileNotFoundException e){ System.out.println("Sorry, could not open" + "'NorthingAndEastings.txt' for reading. Stopping"); System.exit(-1); } // For debugging only for (Map.Entry me : dict.entrySet()){ System.out.println("Name: "+me.getKey() + " Loc: " + me.getValue()); } }}在run()首先在 main 中调用的方法中,HashMap成员变量是从文本文件中填充的。但是当代码转到我想显示HashMap项目的 FX 时,字典是空的。我得到{};
添加回答
举报
0/150
提交
取消