java - org.json.JSONObject 无法转换为 Serialized_JSONObject

标签 java casting

enter image description here我在转换时收到以下错误

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_JSONObjectJsonObject 的子类,所以你不能将 JosnObject 的对象转换为子类对象。您可以通过 READ_NO_VALIDATION.getClass() 来调试 READ_NO_VALIDATION 是哪个类的对象。

关于java - org.json.JSONObject 无法转换为 Serialized_JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50725842/

相关文章:

java - Grails 应用程序,使用 java-apns

java - 如何在 Scala 中忽略 "NullPointerException"并继续完成 MapReduce 任务的下一个工作?

sql - Spark如何比较boolean和string类型的数据

c - 对 C 函数的返回值进行类型转换是否可以接受?

c# - 哪个代码更好 : using "as" or "is"?

Sqlite:如何为 BLOB 转换(数据作为文本)

javascript - 使用可选属性实例化类的正确方法

java - 如何为我的 BaseAdapter ListView 实现 Collection 按钮?

java - 使用外部点查找矩形内部

java - Pusher:减少连接状态的超时