Caused by: java.util.concurrent.ExecutionException: java.lang.ClassCastException: org.json.JSONObject cannot be cast to NCRB_GUIs.DeviceGroupManager.FetcherForms.Serializable_JSONObject
我的 Serialized_JSONObject 定义为:
import java.io.Serializable;
import org.json.JSONObject;
public class Serializable_JSONObject extends JSONObject implements Serializable{}
我不确定为什么会收到此错误。这是抛出异常的代码...
@Override
public ReturnInterface<Serializable_JSONObject> call() throws Exception {
CredentialInterface ci = (CredentialInterface) this.taskDeployInterface;
JSONObject READ_NO_VALIDATION = WebGet.READ_NO_VALIDATION(ci.getUser(), ci.getPassword(), new URL(ci.getHost()));
Serializable_JSONObject o = (Serializable_JSONObject) READ_NO_VALIDATION;//Error thrown here
this.returnItem = o;
return this;
}
最佳答案
我相信此问题是在 WebGet.READ_NO_VALIDATION(ci.getUser(), ci.getPassword(), new URL(ci.getHost()));
代码行重新运行对象时发生的JsonObject
不是 Serialized_JSONObject
并且因为 Serialized_JSONObject
是 JsonObject
的子类,所以你不能将 JosnObject 的对象转换为子类对象。您可以通过 READ_NO_VALIDATION.getClass() 来调试 READ_NO_VALIDATION 是哪个类的对象。
关于java - org.json.JSONObject 无法转换为 Serialized_JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50725842/