gpt4 book ai didi

java - Primefaces TreeTable - 无法实例化类

转载 作者:行者123 更新时间:2023-11-30 09:33:51 25 4
gpt4 key购买 nike

我正在尝试从我正在解析的属性文件创建一个树表,但我不断收到以下代码的错误“无法实例化类”。我不确定为什么它会抛出这个异常。

for(Map.Entry<Object, Object> prop : props.entrySet()) {
String key = ((String)prop.getKey()).replace("_", " ");
String value = (String)prop.getValue();

String[] parts = key.split("\\.");

if(parts.length > 4) {
boolean topLevelExists = false;

// if there are already child nodes
if(root.getChildCount() > 0) {
for(TreeNode n : root.getChildren()) {
System.out.println("n = "+n);
System.out.println("n.data = "+((Menu)n.getData()).getName());
System.out.println("n.getType = "+n.getType());

if(n.getType().equals(parts[2])) {
System.out.println("they equal");
topLevelExists = true;
if(topLevelExists == true) {
System.out.println("topLevelExists");
TreeNode node = new DefaultTreeNode(parts[2], new Menu(parts[2], value), n);
}
} else {
TreeNode node = new DefaultTreeNode(parts[2], new Menu(parts[2], value), root); // FAILS ON THIS LINE WITH THE EXCEPTION BELOW
}
}
// else we are creating the first node
} else {
TreeNode node = new DefaultTreeNode(parts[2], new Menu(parts[2], value), root);
}


}
}

菜单.java

public class Menu {

private String name;
private String path;

public Menu(String name, String path) {
this.name = name;
this.path = path;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}

抛出异常

com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: edu.mayo.ccs.alliance.menu.backing.MenuBacking.
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:193)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:69)
at org.apache.el.parser.AstValue.getValue(AstValue.java:112)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:193)
at org.primefaces.component.api.UITree.getValue(UITree.java:99)
at org.primefaces.component.treetable.TreeTableRenderer.encodeTbody(TreeTableRenderer.java:260)
at org.primefaces.component.treetable.TreeTableRenderer.encodeRegularMarkup(TreeTableRenderer.java:208)
at org.primefaces.component.treetable.TreeTableRenderer.encodeMarkup(TreeTableRenderer.java:132)
at org.primefaces.component.treetable.TreeTableRenderer.encodeEnd(TreeTableRenderer.java:88)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:884)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1681)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:854)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1674)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1677)
at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTab(AccordionPanelRenderer.java:218)
at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTabs(AccordionPanelRenderer.java:147)
at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeMarkup(AccordionPanelRenderer.java:91)
at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeEnd(AccordionPanelRenderer.java:71)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:884)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1681)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1677)
at org.primefaces.component.tabview.TabViewRenderer.encodeTabContent(TabViewRenderer.java:279)
at org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:237)
at org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:128)
at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:69)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:884)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1681)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1677)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1677)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:509)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at edu.mayo.ccs.alliance.util.BrowserNotSupportedFilter.doFilter(BrowserNotSupportedFilter.java:151)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at edu.mayo.ccs.ctsu.sso.CustomAuthenticator.invoke(CustomAuthenticator.java:42)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at edu.mayo.ccs.alliance.menu.backing.MenuBacking.parseMenu(MenuBacking.java:151)
at edu.mayo.ccs.alliance.menu.backing.MenuBacking.<init>(MenuBacking.java:96)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
... 64 more

最佳答案

至此,您正在修改 root,同时您仍在对其进行迭代。

for (TreeNode n : root.getChildren()) {
// ...
TreeNode node = new DefaultTreeNode(parts[2], new Menu(parts[2], value), root); // FAILS ON THIS LINE WITH THE EXCEPTION BELOW
// ...
}

new DefaultTreeNode 将添加 new Menu 作为给定 root 的子节点。但是,这将导致迭代失败,因为后备集合已同时被修改。这就是 ConcurrentModificationException 试图告诉您的全部内容。

您需要相应地重写代码,以便在遍历 root 时不会创建 rootnew DefaultTreeMode 子级>。我基本上可以看到 2 种方法来解决这个问题:重新设计代码,这样你就不需要遍历 root 了,或者在一些 List 中收集新的 child 或 Map 然后将它们添加到 root。具体的功能需求不是很清楚,所以我不能建议哪一个是正确的解决方案。

关于java - Primefaces TreeTable - 无法实例化类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11990618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com