| Summary: | Unhandled exception type IOException when running Main.java | ||
|---|---|---|---|
| Product: | River-Crossing-Puzzle-Solver | Reporter: | tsunychau2-c |
| Component: | Solver Mode | Assignee: | tsunychau2-c |
| Status: | RESOLVED FIXED | ||
| Severity: | major | ||
| Priority: | Normal | ||
| Version: | v0.9.5 | ||
| Hardware: | PC | ||
| OS: | Mac OS | ||
|
Description
tsunychau2-c
2022-11-05 21:55:01 HKT
Bug is confirmed Inside Puzzle.java, Puzzle constructor should surround with "try and catch" to prevent the error shown.
Modification of code:
public Puzzle(String path) {
JSONObject jsonObj = null;
try {
Path file = Path.of(path);
String obj = Files.readString(file);
jsonObj = new JSONObject(obj);
// store the JSON obj, for other classes to access
this.puzzleJSON = jsonObj;
name = (String)jsonObj.get("PuzzleName");
description = (String) jsonObj.get("Description");
roleList = jsonArray2arrayList((JSONArray) jsonObj.get("Roles"));
JSONArray jsonArray;
jsonArray = (JSONArray) jsonObj.get("InitialState");
initialState = new PuzzleState(jsonArray2arrayList((JSONArray) jsonArray.get(0)),
jsonArray2arrayList((JSONArray) jsonArray.get(1)), 0);
jsonArray = (JSONArray) jsonObj.get("TargetState");
targetState = new PuzzleState(jsonArray2arrayList((JSONArray) jsonArray.get(0)),
jsonArray2arrayList((JSONArray) jsonArray.get(1)), 0);
travelables = new HashSet<String>(jsonArray2arrayList((JSONArray) jsonObj.get("Travelable")));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
|