При получении значения из объекта JSON произошло исключение ObjectCollectedException - PullRequest
0 голосов
/ 16 июня 2020

Я получаю

com.sun.jdi.ObjectCollectedException occurred while retrieving value

при чтении файла. json и помещаю значение в HashMap. Я получил значение в моем объекте json на несколько секунд, после чего я вижу сообщение об ошибке как «Неизвестное значение» (com.sun.jdi.ObjectCollectedException occurred while retrieving value)

Ниже приведен код, который я написал. Я прикрепил снимок экрана с сообщением об ошибке

Map < String, JSONObject > i18nLables = new HashMap < String, JSONObject > ();
//Read the properties file  for file location 
Properties properties = myUtil.getProperties("label.properties");
String path = properties.getProperty("label.file.location");
File directoryToRead = new File(path);

if (directoryToRead.isDirectory() && directoryToRead.listFiles().length > 0) {

    File[] allFilesInDirectory = directoryToRead.listFiles();
    for (File file: allFilesInDirectory) {

        try (InputStream stream = new FileInputStream(file.toString())) {

            JSONParser parser = new JSONParser();
            JSONParser jsonParser = new JSONParser();
            JSONObject jsobj = (JSONObject) jsonParser.parse(
                new InputStreamReader(stream, "UTF-8"));

            String fileName = file.getName();

            //key - en or fr..etc
            //value - JSON object
            i18nLables.put(fileName.split("_")[1].substring(0, 2), jsobj);
        } catch (ObjectStreamException e) {
            e.printStackTrace();
        }
    }

}
return i18nLables;

Ниже приведено сообщение об ошибке при отладке кода выше

...