Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中将JSONObject存储在ArrayList中_Java_Arraylist - Fatal编程技术网

在Java中将JSONObject存储在ArrayList中

在Java中将JSONObject存储在ArrayList中,java,arraylist,Java,Arraylist,我试图在ArrayList中存储多个JSONObject,以便在稍后的阶段在tableview中进行解析和显示 出于某种奇怪的原因,我无法将对象添加到列表中 I am using javax.json 以下是我的声明: try { JsonReader jsonReader = Json.creatReader(new StringReader(test)); JsonObject obj = jsonReader.readObject(); jsonReader.cl

我试图在ArrayList中存储多个JSONObject,以便在稍后的阶段在tableview中进行解析和显示

出于某种奇怪的原因,我无法将对象添加到列表中

I am using javax.json
以下是我的声明:

try {
    JsonReader jsonReader = Json.creatReader(new StringReader(test));
    JsonObject obj = jsonReader.readObject();
    jsonReader.close();
    key = obj.getString("key"); // this works with no issue
    ArrayList<JsonObject> jsonList = new ArrayList<>();
    jsonList.add(obj); // everything hangs with no errors when I try to do this

}
如果我对这些行进行了注释,一切都会按预期进行

ArrayList<JsonObject> jsonList = new ArrayList<>();
jsonList.add(obj); 
ArrayList jsonList=new ArrayList();
jsonList.add(obj);

当它们没有被注释时,我将得到catch final throwable(确保在失败原因之后设置状态。

使用调试器并暂停执行,以查看应用程序挂起的位置。
jsonList的状态与此无关。
如果应用程序挂起,则表示线程(可能是主线程)您正在运行的代码由于某种原因被阻止。请暂停调试器中的执行并检查主线程。它应该向您显示一个调用堆栈,指示下一条指令是什么,它将被阻止。这当然取决于您正在使用的工具/调试器。如果移动
jsonReader.close()
到try块的末尾?它仍然不工作,请查看更新您应该在
finally
块中关闭读卡器,但我认为这不是问题所在
ArrayList<JsonObject> jsonList = new ArrayList<>();
jsonList.add(obj);