Hi,
ich kriege folgende Fehlermeldung:
Auftreten tut der Fehler bei folgendem Code:
Der Fehler wird ausgelöst durch das UpdateUI(), so weit zumindest meine Beobachtungen. Wie kann ich aber die Tabelle mit dem neuen Inhalt neu zeichnen, ohne dass dieser Fehler auftritt?
ich kriege folgende Fehlermeldung:
Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
Auftreten tut der Fehler bei folgendem Code:
Code:
public SimpleTableFrame()
{
super("Mercator");
app = new AppTier();
m_simpleTableModel = new SimpleTableModel(m_shoppingList.getArticles());
m_simpleTable = new JTable(m_simpleTableModel);
JSplitPane splitPaneTop = new JSplitPane();
getContentPane().add(splitPaneTop, BorderLayout.CENTER);
splitPaneTop.setOrientation(JSplitPane.VERTICAL_SPLIT);
getContentPane().add(splitPaneTop);
JPanel pPaneTop = new JPanel();
splitPaneTop.setTopComponent(pPaneTop);
pPaneTop.setLayout(new FlowLayout());
pPaneTop.setMinimumSize(new Dimension(600, 25));
JLabel l_shoppingList = new JLabel();
pPaneTop.add(l_shoppingList);
l_shoppingList.setText("Einkaufsliste");
{
//creating a vertical split pane and adding it to the frame
JSplitPane splitPane = new JSplitPane();
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitPaneTop.add(splitPane, JSplitPane.RIGHT);
{
//Add the JTable to the scroll pane to handle table
//scrolling and to display the table header which displays
//the column names
JScrollPane scrollPane = new JScrollPane(m_simpleTable);
scrollPane.setMinimumSize(new java.awt.Dimension(600,180));
//add the scroll pane to the top of the split pane
splitPane.setTopComponent(scrollPane);
}
//add a new pane to the bottom of the split pane
JPanel pPane = new JPanel();
splitPane.setBottomComponent(pPane);
pPane.revalidate();
// Menübalken einfügen
JMenuBar jMenuBar1 = new JMenuBar();
setJMenuBar(jMenuBar1);
{
JMenu jMenu1 = new JMenu();
jMenuBar1.add(jMenu1);
jMenu1.setText("Menü");
{
JMenuItem MenOpenFile = new JMenuItem("Öffne Einkaufliste");
jMenu1.add(MenOpenFile);
MenOpenFile.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
JFileChooser FileChooser = new JFileChooser(path);
FileChooser.addChoosableFileFilter(new MyFilter());
int returnVal = FileChooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File selectedFile = FileChooser.getSelectedFile();
System.out.println(""+selectedFile);
String ParseFile = ("" + selectedFile);
m_shoppingList.getArticles().clear();
try
{
m_shoppingList = app.load(ParseFile, m_shoppingList);
}
catch (IOException ioe)
{
String message = ioe.getMessage();
error(message);
}
m_simpleTable.updateUI();
}
}
});
}
}
Code:
public ShoppingList load(String fileName, ShoppingList shoppingList) throws IOException
{
dat.parsing(fileName);
// analysis
dat.analysis(shoppingList);
return shoppingList;
}
Code:
public void parsing(String param)
{
File fFile = new File(param);
boolean load=fFile.canRead();
if (load == true)
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(fFile);
}
catch (SAXParseException error)
{
System.out.println("\n+++Parse Error++++" + "\nZeile: " + error.getLineNumber() + "\nDatei: " + error.getSystemId());
System.out.println("\n" + error.getMessage());
}
catch (ParserConfigurationException pce){pce.printStackTrace ();}
catch (IOException ioe){ioe.printStackTrace();}
catch (Throwable t){t.printStackTrace();}
}
else{System.out.println("Datei existiert nicht!");}
}
Code:
public ShoppingList analysis(ShoppingList shoppingList) throws IOException
{
int a, num_undertags, b;
NodeList tagliste=document.getElementsByTagName("Article");
NodeList ChildTags;
int num=tagliste.getLength();
Node tag;
String a_Name = new String();
String a_Category = new String();
String a_Unit = new String();
int a_Amount = 0;
int a_PPE = 0;
boolean a_Purchased = false;
short TagTyp;
if (num == 0)
{
throw new IOException ("Datei ist keine Einkaufsliste");
}
for (a=0;a<num; a++)
{
ChildTags=tagliste.item(a).getChildNodes();
num_undertags=ChildTags.getLength();
for(b=0; b<num_undertags; b++)
{
tag=ChildTags.item(b);
TagTyp=tag.getNodeType();
if (TagTyp==Node.ELEMENT_NODE)
{
if (tag.getNodeName().equals("Label"))
{
a_Name = tag.getFirstChild().getNodeValue();
}
if (tag.getNodeName().equals("Type"))
{
a_Category = tag.getFirstChild().getNodeValue();
}
if (tag.getNodeName().equals("UnitLabel"))
{
a_Unit = tag.getFirstChild().getNodeValue();
}
if (tag.getNodeName().equals("Amount"))
{
a_Amount = Integer.parseInt(tag.getFirstChild().getNodeValue());
}
if (tag.getNodeName().equals("PricePerUnit"))
{
a_PPE = Integer.parseInt(tag.getFirstChild().getNodeValue());
}
if (tag.getNodeName().equals("Purchased"))
{
String boolSave = (""+tag.getFirstChild().getNodeValue());
if (boolSave.equals("true"))
{
a_Purchased = true;
}
if (boolSave.equals("false"))
{
a_Purchased= false;
}
}
}
}
shoppingList.getArticles().addElement(new Article(a_Name, a_Category, a_Amount, a_PPE, a_Unit, a_Purchased));
}
NodeList tagliste2=document.getElementsByTagName("PurchasedDate");
System.out.println("Datum:" + tagliste2.item(0).getFirstChild().getNodeValue());
try
{
DateFormat dft = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZ");
//TODO
// shoppingList.setPurchaseDate(dft.parse(tagliste2.item(0).getFirstChild().getNodeValue()));
}
catch(Exception e)
{
}
tagliste2=document.getElementsByTagName("Shop");
System.out.println("Laden: " + tagliste2.item(0).getFirstChild().getNodeValue());
return shoppingList;
}
Der Fehler wird ausgelöst durch das UpdateUI(), so weit zumindest meine Beobachtungen. Wie kann ich aber die Tabelle mit dem neuen Inhalt neu zeichnen, ohne dass dieser Fehler auftritt?