下面是我运行服务器时从netbeans IDE得到的错误。错误显示
不可编译的源代码-项目。ApplicationMenu不是抽象的并且不重写中的抽象方法setProject(Projects.Project(项目。抽象组件
但是没有错误。我检查了Menu超类,它确实覆盖了抽象方法。
Exception in thread "main" java.lang.ExceptionInInitializerError
at Projects.Project.initialize(Project.java:54)
at Projects.Project.<init>(Project.java:34)
at Server.FileIO.ProjectIO.ProjectIO.translate(ProjectIO.java:52)
at Server.FileIO.ProjectService.LoadProjects(ProjectService.java:55)
at Server.FileIO.ProjectService.<init>(ProjectService.java:42)
at Server.FileIO.FileService.<init>(FileService.java:35)
at Server.ServerInitialization.InitializeModelAndProjects(ServerInitialization.java:47)
at Server.Server.Initialize(Server.java:97)
at Server.Server.<init>(Server.java:46)
at Server.Server.main(Server.java:39)
Caused by: java.lang.RuntimeException: Uncompilable source code - Projects.ApplicationMenu is not abstract and does not override abstract method setProject(Projects.Project) in Projects.AbstractComponent
at Projects.UIComponent.<clinit>(UIComponent.java:15)
... 10 more
下面是ApplicationMenu类:
package Projects;
import Key.Key;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
/**
*
* @author Mark
*/
public class ApplicationMenu extends Menu{
MenuBar menubar;
ApplicationMenu parentmenu;
public ApplicationMenu(String name, MenuBar menubar, Key key) {
super(name, null, key, menubar.project);
this.menubar = menubar;
}
public ApplicationMenu(String name, ApplicationMenu parentmenu, Key key){
super(name, parentmenu, key, parentmenu.project);
}
public ApplicationMenu(JsonObject jsonApplicationMenu, String name, MenuBar menubar, Key key){
super(name, null, key, menubar.project);
this.menubar = menubar;
this.unPackComponent();
}
public ApplicationMenu addApplicationMenu(String name, Key key){
ApplicationMenu menu = new ApplicationMenu(name, this, key);
this.addChildMenu(menu);
return menu;
}
public ComponentMenu addComponentMenu(String name, Key key){
ComponentMenu menu = new ComponentMenu(name, this, key);
this.addChildMenu(menu);
return menu;
}
@Override
public JsonObject packComponent(){
JsonArrayBuilder arraybuilder = Json.createArrayBuilder();
this.childmenus.forEach((cmkey,menu)->{
arraybuilder.add(menu.packComponent());
});
packagedJsonArray = arraybuilder.build();
packagedJsonObject = Json.createObjectBuilder()
.add(Menu.childMenus(), packagedJsonArray)
.add( Menu.menuType(), ApplicationMenu.applicationMenu())
.add(AbstractComponent.name(), this.name)
.add(Key.key(),this.packKey()).build();
return packagedJsonObject;
}
public final static String applicationMenu(){return "ApplicationMenu";}
@Override
public final void unPackComponent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
void translateFromHeFile() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
下面是ApplicationMenu的Menu超类:
package Projects;
import Key.Key;
import java.util.HashMap;
/**
*
* @author Mark
*/
public abstract class Menu extends UIComponent{
Menu parentMenu;
HashMap<Key, Menu> childmenus;
public Menu(String name, Menu parentMenu, Key key, Project project) {
super(name, parentMenu, key);
this.parentMenu = parentMenu;
childmenus = new HashMap<>();//
this.project = project;
}
public Menu addChildMenu(Menu menu){
childmenus.put(menu.key, menu);
return menu;
}
public String getName(){
return this.name;
}
@Override
protected void setProject(Project project){
this.project = project;
}
@Override
public Project getProject(){
return this.project;
}
public final static String childMenus(){return "ChildMenus";}
public final static String menuType(){return "MenuType";}
}
正如你所看到的,我确实覆盖了那个方法。我已经尝试过多次重新启动IDE。我还多次尝试清理和构建我所有的依赖项目。我做的一件事是在项目之间移动一个包。我意识到由于某些依赖关系,我无法将此包移到通用项目中。在我把它移回来之后,我开始出现这个错误。如有任何协助,我们将不胜感激。
下面是AbstractComponent类:
package Projects;
import Key.Key;
import java.util.HashMap;
import javax.json.JsonArray;
import javax.json.JsonObject;
/**
*
* @author Mark
*/
public abstract class AbstractComponent implements Component {
String name;
Key key;
AbstractComponent parentComponent;
HashMap<Key, AbstractComponent> childComponents;
JsonObject packagedJsonObject;
JsonArray packagedJsonArray;
Project project;
public AbstractComponent( String name, AbstractComponent parentComponent, Key key){
this.name = name;
this.parentComponent = parentComponent;
this.key = key;
childComponents = new HashMap<>();
}
public AbstractComponent addChild(AbstractComponent projectelement){
childComponents.put(projectelement.key, projectelement);
return projectelement;
}
@Override
public Key getKey(){
return this.key;
}
public JsonObject packKey(){
return this.key.toJsonObject();
}
abstract JsonObject packComponent();
abstract void unPackComponent();
abstract void translateFromHeFile();
abstract protected void setProject(Project project);
public final static String name(){return "Name";}
}
我猜setProject方法源自另一个包中声明的接口或父类,可能是Component接口。如果是这样,那么抽象类会编译得很好,但一旦您试图重写在不同包中声明的受保护方法,具体类就会失败。
如果是这样,那么解决方案就是公开setProject。