So, I'm trying to load some values from a JSON file:
{
Float :
null
,
test :
"hello"
,
Int :
2
}
However, the method I have below isn't working at all and doesn't load the file contents. No errors are thrown other than NPEs when I try to use various methods that return values loaded from the file. Any idea what I'm doing wrong?
protected void load(String name, String path) throws FileAlreadyLoadedException{
if (get(name) == null){
final ThunderFile tf = new ThunderFile(name, path);
//files.add(tf);
try {
final JSONObject jobj = (JSONObject)new JSONParser().parse(new FileReader(path + File.separator + name + ".json"));
new Thread(){
public void run(){
Iterator<?> i = jobj.keySet().iterator();
while(i.hasNext()){
String key = (String) i.next();
Object value = jobj.get(key);
if (!key.equals("") && !value.equals("")){
tf.set(key, value);
}
}
files.add(tf);
System.out.println("[Thunderbolt 2] Loaded " + tf.getName() + ".json");
this.interrupt();
}
}.start();
} catch(IOException | ParseException e) {
e.printStackTrace();
}
}else{
throw new FileAlreadyLoadedException("The File " + name + ".json is already loaded!");
}
}
EDIT: To clarify, no values are loaded, even if my file looked like this:
{"Double":2.0}