Hi, ich habe nochmal eine Frage.
Ich habe eine Tabelle, in der ich MP3 Dateien anzeigen lassen will, also mit Titel,Interpret und so.
Das klappt eigentlich auch.
Doch wenn die Tabelle dann sichtbar wird, kommt die ganze Zeit so eine Exception.
Hier die Exception:
Wisst ihr woran das liegen könnte?
Ich habe eine Tabelle, in der ich MP3 Dateien anzeigen lassen will, also mit Titel,Interpret und so.
Das klappt eigentlich auch.
Doch wenn die Tabelle dann sichtbar wird, kommt die ganze Zeit so eine Exception.
Code:
Hier erst mal das Tablemodel:
import java.io.*;
import java.util.*;
import javax.swing.table.*;
import org.farng.mp3.*;
import org.farng.mp3.id3.*;
public class Listmodel extends AbstractTableModel {
MusikPlayer m;
ArrayList<File> lieder = new ArrayList<File>();
public Listmodel(MusikPlayer m) {
this.m = m;
addFile(new File("/home/kai/mp3/"));
}
public int getColumnCount() {
return 4;
}
public int getRowCount() {
return lieder.size();
}
public Object getValueAt(int row, int col) {
try {
MP3File file = new MP3File(lieder.get(row));
AbstractID3v2 f = file.getID3v2Tag();
if(col==0) return f.getSongTitle();
if(col==1) return f.getLeadArtist();
if(col==2) return f.getAlbumTitle();
if(col==3) return f.getSongGenre();
} catch (Exception e) {
e.printStackTrace();
}
return lieder.get(row);
}
public String getColumnName(int col) {
String header="";
if(col==0) header= "Titel";
if(col==1) header= "Interpret";
if(col==2) header= "Album";
if(col==3) header= "Genre";
return header;
}
public void addFile(File f) {
System.out.println(f);
if(f.isDirectory()) {
File[] files = f.listFiles();
for(int i=0; i<files.length; i++) {
addFile(files[i]);
}
}
else {
lieder.add(f);
}
}
}
Code:
java.lang.NullPointerException
at Listmodel.getValueAt(Listmodel.java:33)
at javax.swing.JTable.getValueAt(JTable.java:2652)
at javax.swing.JTable.prepareRenderer(JTable.java:5666)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2067)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1969)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1765)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:758)
at javax.swing.JComponent.paint(JComponent.java:1022)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
at javax.swing.RepaintManager.paint(RepaintManager.java:1132)
at javax.swing.JComponent.paint(JComponent.java:1008)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1797)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:738)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:683)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:663)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Wisst ihr woran das liegen könnte?