NullPointerException in invokeLater while running through Java Webstart

前端 未结 5 1537
心在旅途
心在旅途 2020-11-29 06:52

After upgraded from JRE 1.7.0_21 to 1.7.0_25-b15 my application started to throw NullPointerException in SwingUtilities.invokeLater(...) when it is run from Java WebStart. S

5条回答
  •  没有蜡笔的小新
    2020-11-29 07:37

    The problem occurs in the Webstart environment. Before Webstart version of Java 7u25 the AppContext was set on the system thread group. Yet it is set on the main thread group.

    If you have a thread based on a thread group where its parent or grandparent is not the main thread group it has no sun.awt.AppContext.

    You should create your thread based on the thread group of the security manager if one exists.

    Runnable task = ....
    ThreadGroup threadGroup = System.getSecurityManager() != null
                                        ? System.getSecurityManager().getThreadGroup()
                                        : Thread.currentThread().getThreadGroup();
    Thread t = new Thread(threadGroup, task, "my thread", 0);
    

提交回复
热议问题