Java 9 reflection error
Problem solving
Question
when writing JavaFX, perform the HTTP request database login operation, and convert the returned JSON string into a class object. The following code always reports an error.
// json string to class object
JavaType javaType;
ResponseBean<T> data = new ObjectMapper().readValue(json, javaType);
the following errors are reported:
java.lang.reflect.InaccessibleObjectException: Unable to make protected cc.nsurl.bean.ResponseBean() accessible: module cc.nsurl.controllers does not "opens cc.nsurl.bean" to module com.fasterxml.jackson.databind
if you can’t open the class, you can’t reflect.
Solution:
Add the file module-info.java to the JavaFX project. The overall project structure is as follows:
-- src
-- main
-- java
-- module-info.java
Configure in this java file:
module cc.nsurl.controllers {
// Classes that require reflection opens Self-written classes to third-party libraries
opens cc.nsurl.controllers to javafx.fxml;
opens cc.nsurl.bean to com.fasterxml.jackson.databind;
exports cc.nsurl.controllers;
}
Read More:
- [Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)
- [Solved] Java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.util.List
- [Solved] JAVA fx Error: java.lang.instrument ASSERTION FAILED ***: “!errorOutstanding“ with message transform
- [Solved] nacos Startup Error: nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error
- java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x590
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] IDEA springboot Startup Error: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path
- [Solved] JAVA Error: Error occurred during initialization of boot layer java.lang.module.FindException
- Java error: java.lang.NoSuchMethodError
- [Solved] java: Internal error in the mapping processor: java.lang.NullPointerException
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- [Solved] JAVA OpenCV Startup Error: java.lang.UnsatisfiedLinkError
- JAVA error: java.lang.OutOfMemoryError:GC overhead limit exceeded
- [Solved] Hbase-shell 2.x Error: Unhandled Java exception: java.lang.IncompatibleClassChangeError: Found class jline.Terminal…
- [Solved] JAVA Project Import jstl Error: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator
- [Solved] fasterxml ToStringSerializerBase Error: Caused by: java.lang.NoClassDefFoundError…
- [Solved] Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- [Solved] Swagger Startup Error: java.lang.NumberFormatException: For input string: ““
- [Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException