쓰려고하는 프로그램에 약간의 문제가 있습니다. 파일 선택기에서 사진을 가져 와서 JPanel에 인쇄하고 싶습니다. 이제 그림의 검색 작동하지만 JLabels 배열에 넣을 수없는 것, 나는 NullPointerException. 나는이 예외가 무엇을 의미하는지 알지만 어디서 어떻게 잘못했는지 누군가가 내 실수를 찾도록 도와 줄 수 있습니까?imageicons로 레이블 배열을 만들 때 nullpointerexception
private class OpenFileHandler implements ActionListener {
public BufferedImage [] getBufferedImages() {
chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new FileNameExtensionFilter("Images", "PNG", "JPG", "GIF", "BMP"));
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
imagesFile = chooser.getSelectedFiles();
}
imagesBuf = new BufferedImage[imagesFile.length];
for (int i = 0; i<imagesFile.length; i++) {
try {
imagesBuf[i] = ImageIO.read(imagesFile[i]);
} catch (IOException e) {
e.printStackTrace();
}
}
return imagesBuf;
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == openMenu) {
getBufferedImages();
for (int i = 0; i<imagesBuf.length; i++) {
labels[i] = new JLabel(new ImageIcon(imagesBuf[i]));
picturePanel.add(labels[i]);
}
}
}
}
그리고 이것은 내가지고있어 오류입니다 :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at be.maarten.gallery.GalleryFrame$OpenFileHandler.actionPerformed(GalleryFrame.java:118)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(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.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.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)
이 클래스의 118 번째 줄은 무엇입니까? –
118 번 줄을 게시하고'picturePanel'은 어디에서 초기화합니까? – Prine
디버거는 아주 유용합니다. picturePanel은 어디에서 초기화합니까? – DaveRlz