0

我正在使用 org.jdesktop.application 依赖项并想加载一些资源。gradle 项目的结构如下:

  • main.java.myproject
  • 主要资源

当我想使用getResourceMap(). 它不读取任何属性,所以我认为这些文件必须存储在main.java.myproject.resources. 如何设置资源映射的路径以保持我的项目结构?

代码示例:

public MyView(SingleFrameApplication app) {
    super(app);
    initComponents();
    ResourceMap resourceMap = getResourceMap();
    resourceMap.getInteger("timeout"); // <-- NullPointerException
}

堆栈跟踪:

Oct 19, 2019 4:00:01 PM org.jdesktop.application.Application$1 run
SEVERE: Application class myproject.MyApp failed to launch
java.lang.NullPointerException
    at myproject.MyView.<init>(MyView.java:156)
    at myproject.MyApp.startup(MyApp.java:30)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Exception in thread "AWT-EventQueue-0" java.lang.Error: Application class myproject.MyApp failed to launch
    at org.jdesktop.application.Application$1.run(Application.java:177)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NullPointerException
Caused by: java.lang.NullPointerException

    at myproject.MyView.<init>(MyView.java:156)
    at myproject.MyApp.startup(MyApp.java:30)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    ... 13 more
4

0 回答 0