问题描述
我正在尝试运行我的简单java程序,但是有一个大问题。
它与GUI连接。它无法显示任何创建的窗口。我附加了堆栈跟踪和一个类。
I'm trying to run my simple java-program, but have a big problem. It's connected with GUI. It can not show any created window. I attach stack-trace and one class.
@ConvertAsProperties(
dtd = "-//org.shop.viewer//ShopViewer//EN",
autostore = false
)
@TopComponent.Description(
preferredID = "ShopViewerTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "explorer", openAtStartup = false)
@ActionID(category = "Window", id = "org.shop.viewer.ShopViewerTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
displayName = "#CTL_ShopViewerAction",
preferredID = "ShopViewerTopComponent"
)
@Messages({
"CTL_ShopViewerAction=ShopViewer",
"CTL_ShopViewerTopComponent=ShopViewer Window",
"HINT_ShopViewerTopComponent=This is a ShopViewer window"
})
public final class ShopViewerTopComponent extends TopComponent {
public ShopViewerTopComponent() {
initComponents();
setName(Bundle.CTL_ShopViewerTopComponent());
setToolTipText(Bundle.HINT_ShopViewerTopComponent());
EntityManager entityManager = Persistence.createEntityManagerFactory("ShopLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("Shops.findAll");
List<Shops> resultList = query.getResultList();
for (Shops c : resultList) {
jTextArea1.append(c.getTitle() +"dqwdqwdqwdqwd"+ "\n");
}
}
java.lang.IllegalStateException: Cannot find TopComponent with preferredID ShopViewerTopComponent, see IDE log for more details.
at org.openide.windows.OpenComponentAction.actionPerformed(OpenComponentAction.java:91)
at org.openide.awt.AlwaysEnabledAction$1.run(AlwaysEnabledAction.java:198)
at org.openide.util.actions.ActionInvoker$1.run(ActionInvoker.java:95)
at org.openide.util.actions.ActionInvoker.doPerformAction(ActionInvoker.java:116)
at org.openide.util.actions.ActionInvoker.invokeAction(ActionInvoker.java:99)
at org.openide.awt.AlwaysEnabledAction.actionPerformed(AlwaysEnabledAction.java:201)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
我认为在TopComponent构造函数中有一个错误。
I think that a misstake is in TopComponent-constructor.
非常感谢。
推荐答案
在加载TopComponent之前出现问题时,此问题无法找到具有preferredID的TopCoponent ...。
This problem "cannot find TopCoponent with preferredID..." happens frequently when a problem occurs before loading the TopComponent.
一个简单的例子:你尝试在失败的构造函数中加载一些东西(在任何深度)。
A simple example : you try to load something in the constructor that fails (at any depth).
这个未显式的消息我疯了不止一次!
This unexplicit message made me mad more than once !
希望这有帮助。
这篇关于找不到具有preferredID的TopComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!