我正在尝试运行我的简单Java程序,但是有一个大问题。
它与GUI连接。它无法显示任何创建的窗口。我附加了堆栈跟踪和一个类。

@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-constructor中有一个错误。

非常感谢。

最佳答案

在加载TopComponent之前发生问题时,经常会出现“无法找到带有PreferredID的TopCoponent ...”的问题。

一个简单的例子:您尝试在构造函数中加载失败的内容(任何深度)。

这个不明确的信息使我不止一次生气!

希望这可以帮助。

07-24 09:17