jfc: adding tab

A

Andreas Bauer

Hi,

I want to load a properties file. I have a class, which returns
a hashtable with all the value. Then in my gui I have
loadActionPerformed-method

private void loadActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
JFileChooser jfc = new JFileChooser();
jfc.showDialog(workingwindow,"Open");
FileFilters filter = new FileFilters();
File file = jfc.getSelectedFile();
LoadProperties lp = new LoadProperties(file);
JPanel jp = new JPanel();
workingwindow.addTab(jfc.getName(),jp);
Hashtable ht = (Hashtable) lp.loadProperties();
Enumeration props = ht.elements();
while(props.hasMoreElements()){
String key = (String) props.nextElement().toString();
String value = (String) ht.get(key);
jp.add(new JLabel(value));
jp.add(new JTextField(value));
}

But that doesn't work. I get a nullpointerexception.
What have I forgotten?

Thanks in advance for any hint.

Regards,

Andi
 
T

Thomas Weidenfeller

Andreas said:
But that doesn't work.

This is the error "description" people hate most here. It is of
absolutely no value, because we don't have magic powers. So please write
some meaningful error description. This should include a complete
example (follow the advice given in
http://www.physci.org/codes/sscce.jsp) and the complete, error message
as given by the compiler (not shortened, not paraphrased).

/Thomas
 
A

Andreas Bauer

private void loadActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser jfc = new JFileChooser();
jfc.showDialog(workingwindow,"Open");
FileFilters filter = new FileFilters();
File file = jfc.getSelectedFile();
LoadProperties lp = new LoadProperties(file);
JPanel jp = new JPanel();
workingwindow.addTab(jfc.getName(),jp);
Hashtable ht = (Hashtable) lp.loadProperties();
Enumeration props = ht.elements();
while(props.hasMoreElements()){
String key = (String) props.nextElement().toString();
String value = (String) ht.get(key);
jp.add(new JLabel(value));
jp.add(new JTextField(value));
}

File file = jfc.getSelectedFile();
No file is selected, although getSelectedFile() should return a file.
So I get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at
com.brotkasting.prozessgui.LoadProperties.loadProperties(LoadProperties.java:33)
at
com.brotkasting.prozessgui.ProzessGUI.loadActionPerformed(ProzessGUI.java:154)

the loadProperties Method:

try{
FileInputStream fis = new FileInputStream(file);
props.load(fis);
ht = (Hashtable) props.propertyNames();
String test ="EE";
}catch.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top