简体   繁体   中英

Error in converting an object with JavaFX CheckBox attribute to a JSON string using GSON

To explain things briefly, I have a Task object I want to convert to a JSON string using the GSON library. The object itself has String and int attributes, which I can convert to JSON just fine, however when I add a CheckBox attribute to the class, this error message appears

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private javafx.beans.property.BooleanProperty javafx.scene.control.CheckBox.indeterminate accessible: module javafx.controls does not "opens javafx.scene.control" to module gson at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:349) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:289) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:174) at java.base/java.lang.reflect.Field.setAccessible(Field.java: 168) at gson@2.8.2/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:157) at gson@2.8.2/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) at gson@2.8.2/com.google.gson.Gson.getAdapter(Gson.java:423) at gson@2.8.2/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115) at gson@2.8.2/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164) at gson@2.8.2/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory .create(ReflectiveTypeAdapterFactory.java:100) at gson@2.8.2/com.google.gson.Gson.getAdapter(Gson.java:423) at gson@2.8.2/com.google.gson.Gson.toJson(Gson.java:661) at gson@2.8.2/com.google.gson.Gson.toJson(Gson.java:648) at gson@2.8.2/com.google.gson.Gson.toJson(Gson.java:603) at gson@2.8.2/com.google.gson.Gson.toJson(Gson.java:583) at IAssessment/application.AddTaskController.addTask(AddTaskController.java:45)

I had something similar beforehand and I asked about it here (the error message was ending in does not export to gson) and the solution was to create a class module-info that looks like this

exports snippet;
exports application;
requires gson;
requires java.sql;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
requires javafx.graphics;
opens application to gson, javafx.fxml;

This solved my previous problem but this seems to be a similar problem for which I don't know what to do. So is there a way to solve it? I appreciate any and all help.

Figured it out

(tablecolumnname).setCellFactory(new Callback<TableColumn<(object), Boolean>, TableCell<(object), Boolean>>() {

        public TableCell<(object), Boolean> call(TableColumn<(object), Boolean> p) {
            return new CheckBoxTableCell<(object), Boolean>();
        }

    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM