Unable to make public void GenericExercise.GenericExercise_homework01.Testlist() accessible: module chapter15 does not "exports GenericExercise" to module junit
时间: 2024-04-08 16:35:05 浏览: 14
这个错误提示是由于在模块`chapter15`中没有将`GenericExercise`导出到`junit`模块导致的。在Java 9及更高版本中,模块系统被引入,模块之间需要明确声明导出和导入的关系。
要解决这个问题,你需要在`chapter15`模块中将`GenericExercise`导出给`junit`模块。你可以在`module-info.java`文件中添加导出声明,类似这样:
```java
module chapter15 {
exports GenericExercise to junit;
}
```
这样就可以使`GenericExercise`类对`junit`模块可见,并且可以访问其中的公共方法。
请注意,这只是一个示例,具体的导出规则可能根据你的项目结构和需求而有所不同。你需要根据实际情况调整模块声明和导出的配置。
相关问题
Unable to make public void GenericExercise.Homework01.Testlist() accessible: module chapter15 does not "exports GenericExercise" to module junit
这错误是因为在JUnit中,你试图访问`GenericExerciseomework01.Testlist()`方法,但是`GenericExercise`模块并没有对外导出(exports)给`junit`模块。这意味着在JUnit中无法访问`GenericExercise`模块的类或方法。
要解决这个问题,你可以在`GenericExercise`模块的`module-info.java`文件中添加对`junit`模块的导出声明。例如:
```java
module GenericExercise {
exports GenericExercise to junit;
}
```
这样就可以将`GenericExercise`模块对外导出给`junit`模块,使得JUnit测试能够访问其中的类和方法。记得重新编译并运行你的代码,这个错误应该就会消失了。
java.lang.reflect.InaccessibleObjectException: Unable to make public void GenericExercise.Homework01.Testlist() accessible: module chapter15 does not "exports GenericExercise" to module junit
这个异常是由于模块之间的访问权限限制导致的。根据异常信息,看起来你的代码中的模块 "chapter15" 没有将 "GenericExercise" 导出给模块 "junit",因此在 "junit" 模块中无法访问 "GenericExercise.Homework01.Testlist()" 方法。
要解决这个问题,你可以在 "chapter15" 模块的 module-info.java 文件中使用 "exports" 关键字将 "GenericExercise" 导出给 "junit" 模块。具体做法如下:
```java
module chapter15 {
exports GenericExercise to junit;
}
```
这样做会允许其他模块(如 "junit")访问 "chapter15" 模块中导出的包和类。确保在你的代码中做出相应的更改后,重新编译并运行程序,这个访问权限异常就会得到解决。