ボタンがあり、クリックするとファイルチューザーを開く必要があります...しかし、常にこのNullPointerExceptionが発生します。
イベントdisの外でダイアログを開始しているため、それが可能であると読みました。スレッドですが、この呼び出し EventQueue.invokeLater はとにかく EDT を呼び出しますよね?
ソースは次のとおりです (else if は ActionListener 拡張クラスにあります - actionPerformed メソッドにあります):
else if(buttonID.equals(Definition.BTN_LOAD_DF_NAME))
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter()
{
@Override
public String getDescription(){
return "XML-File";
}
@Override
public boolean accept(File f){
return f.isDirectory() || f.getName().endsWith(".xml") || f.getName().endsWith(".XML");
}
});
int state = fc.showOpenDialog(null);
if(state == JFileChooser.APPROVE_OPTION)
{
try{
app.loadDF(fc.getSelectedFile());
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
});
}
ここにスタックトレース:
Exception occurred during event dispatching:
java.lang.NullPointerException
at sun.swing.plaf.synth.SynthFileChooserUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at java.awt.Window.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at javax.swing.JFileChooser.showDialog(Unknown Source)
at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
at logic.FuncActionListener$1.run(FuncActionListener.java:120)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
いつも助けてくれてありがとう!!
ps: ルック アンド フィール (使用する必要があります):
<?xml version="1.0" encoding="UTF-8"?>
<synth>
<style id="backingStyle">
<opaque value="FALSE" />
</style>
<bind style="backingStyle" type="region" key="Panel" />
<style id="button">
<!-- Shift the text one pixel when pressed -->
<property key="Button.textShiftOffset" type="integer" value="2" />
<state>
<imagePainter method="buttonBackground" path="images/button_normal.png" sourceInsets="10 10 10 10" />
<font name="Dialog" size="12" />
</state>
<state value="PRESSED">
<imagePainter method="buttonBackground" path="images/button_normal_pressed.png" sourceInsets="10 10 10 10" />
</state>
</style>
<bind style="button" type="region" key="Button" />
<style id="wndBG">
<imagePainter methode="wndBackground" path="images/cdu_bg.png" sourceInsets="1 1 1 1"></imagePainter>
</style>
<bind style="wndBG" type="name" key="root"></bind>
</synth>