java - 为什么这个导入不能跨 Eclipse 中的包工作?
问题描述
这是无法编译的 Car 类:
package car;
import engine.Engine;
public class Car {
private Engine engine;
/***
* Constructor
* @param engine The engine that the car object will have
*/
Car(Engine engine) {
engine = new Engine(engine); // Use the Engine copy constructor
}
}
这是引擎包中的引擎类:
package engine;
public class Engine {
private String name;
private int displacement;
public Engine(String name, int displacement) throws Exception {
setName(name);
setDisplacement(displacement);
}
public String getName() {return name;}
public int getDisplacement() {return displacement;}
private void setName(String name) throws Exception {
if (name.trim().length() == 0) {
throw new Exception("Engine name cannot be blank");
}
}
private void setDisplacement(int displacement) throws Exception {
if (displacement < 0) {
throw new Exception("Engine displacement cannot be zero or negative");
}
}
}
解决方案
修复:我没有更改代码,我从工作区中删除了项目,关闭了 Eclipse,用不同的工作区重新打开了 Eclipse,并将相同的项目导入到工作区中。啊。
推荐阅读
- godot - 如何通过 gdscript 在移动壁(StaticBody2D)上 Pinjoint2D 飞镖(Kinematicbody2D)
- matlab - 如何在 EEGLab 中读取 .mat 文件?
- spring - 使用响应式 Mongo 查询获取多个 Mono 对象
- twitter-bootstrap - 引导组按钮仍显示单选按钮
- python - 带有Column命令的pyspark数据框不起作用
- php - 登录脚本有时会访问错误的帐户
- react-native - 在 react-native 的其他组件中找不到变量导航
- python - 使用列表理解返回索引
- python - 在 sklearn python 中使用高斯过程回归时出错
- php - PHP:无法访问 JSON 对象/数组