我想從JFileChooser中選擇歌曲列表後,將音頻信息顯示給jList。這是我得到的東西,但它拋出了一個NullPointerException
。如何在jList中顯示音頻信息
boolean openFile() throws FileNotFoundException{
JFileChooser jfc = new JFileChooser();
jfc.setMultiSelectionEnabled(true);
jfc.setDialogTitle("Open File");
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
jfc.setCurrentDirectory(new File ("."));
jfc.setFileFilter(audiofilter);
int result = jfc.showOpenDialog(this);
if(result == JFileChooser.CANCEL_OPTION){
return true;
}else if(result == JFileChooser.APPROVE_OPTION){
File[] file = jfc.getSelectedFiles();//fFile = jfc.getSelectedFile();
String file_string = fFile.getAbsolutePath();
for(int i=0;i<file.length;i++){
if(file[i].isFile()){
String[] filesInDirectory = file[i].list();
for(int ii=0;ii<filesInDirectory.length;ii++){
list.addElement(filesInDirectory[ii]);
}
}else{
list.addElement(file[i]);
}
}
if(file_string != null){
fTextArea.setText(file_string);
}else{
return false;
}
this.jList1.setModel(list);
}
return true;
}
錯誤說:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at SoundsTrip.SoundBytePlaying.openFile(SoundBytePlaying.java:267)
at SoundsTrip.SoundBytePlaying.jButton1MouseClicked(SoundBytePlaying.java:210)
at SoundsTrip.SoundBytePlaying.access$000(SoundBytePlaying.java:43)
at SoundsTrip.SoundBytePlaying$2.mouseClicked(SoundBytePlaying.java:135)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6270)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
這是怎麼造成的,我該如何解決呢?
沒有必要抱怨。這裏每個人都可以得到同樣的幫只需以聰明的方式提出問題。我清理了一下這個問題。 – BalusC 2011-03-25 02:45:13
謝謝...下次注意... :) – 2011-03-25 02:49:29
和267行是...? – draganstankovic 2011-03-25 02:51:40