VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time ]
Subject: NullPointerException


Author:
Rik VW
[ Next Thread | Previous Thread | Next Message | Previous Message ]
Date Posted: 11:24:48 04/28/02 Sun

Bij een oefening ben ik een rare fout tegengekomen. Data worden in een Vector gestopt (ic Strings). De String zit er zeker in want bij System.out.println(data.elementAt(0)); krijg ik het element terug in de uitvoer. Als ik dan echter een JList die data wil doorgeven geeft hij in runtime een NullPointerException. Oekandana?

Code volgt:

public void actionPerformed(ActionEvent e) {
JButton bron = (JButton) e.getSource();
if (bron == toevoegen) {
data.addElement(vakT.getText() + " " + ptnT.getText());
System.out.println(data.elementAt(0));
//Geeft fout NullPointer alhoewel er wel degelijk iets inzit
lijst.setListData(data);
lijst.repaint();
vakT.setText("");
ptnT.setText("");
tabel = new JScrollPane (lijst);
}
else {
try {
Object []dataArray = data.toArray();
FileWriter fw = new FileWriter (klas);
for (int i=0; i < dataArray.length; i++)
fw.write(dataArray[i]+"\n");
fw.write("*\n");
fw.close();
// Nieuwe namen toevoegen in de klas
Frame namen = new NamenFrame();
// Geen BufferedWriter nodig???
dispose();
} catch (IOException ioex) {
System.out.println(ioex);
}
}
}

[ Next Thread | Previous Thread | Next Message | Previous Message ]

Replies:
Subject Author Date
Re: NullPointerExceptionJohan16:59:00 04/28/02 Sun


Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]


Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.