尝试在我的 java 项目上运行服务器和客户端,该项目由 CLI 和 GUI 制作的棋盘游戏组成。不幸的是,我在添加用户名后出现了这个错误:
Exception in thread "Thread-0" java.lang.reflect.InaccessibleObjectException: Unable to make field private float javafx.scene.paint.Color.red accessible: module javafx.graphics does not "opens javafx.scene.paint" to module gson
这是总错误:
Exception in thread "Thread-0" java.lang.reflect.InaccessibleObjectException: Unable to make field private float javafx.scene.paint.Color.red accessible: module javafx.graphics does not "opens javafx.scene.paint" to module gson
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:341)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:281)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:176)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:170)
at gson@2.8.5/com.google.gson.internal.reflect.UnsafeReflectionAccessor.makeAccessible(UnsafeReflectionAccessor.java:44)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:159)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at gson@2.8.5/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at gson@2.8.5/com.google.gson.Gson.getAdapter(Gson.java:458)
at gson@2.8.5/com.google.gson.Gson.fromJson(Gson.java:926)
at gson@2.8.5/com.google.gson.Gson.fromJson(Gson.java:892)
at gson@2.8.5/com.google.gson.Gson.fromJson(Gson.java:841)
at gson@2.8.5/com.google.gson.Gson.fromJson(Gson.java:813)
at project/controller.JsonUnwrapper.sendJson(JsonUnwrapper.java:99)
at project/network.Socket.JsonRouterSocket.run(JsonRouterSocket.java:55)
at java.base/java.lang.Thread.run(Thread.java:835)
不知何故,javafx 和 GSON 之间似乎存在冲突。有趣的是,我使用 CLI(不需要 javafx)而不是 GUI 运行服务器和客户端。假设 Gson 应该返回一些信息(包括颜色)但是当被调用时!我什至没有执行应该返回我一些 oinfo 的命令!
可以使用 RMI 或 Sockets 进行通信,但错误仍然存在!
此外,这个项目是由我和另外两个人制作的。其中一个使用 Linux,另一个使用 Windows 10(就像我一样),但他们都没有这个问题!