By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

Program won't compile

P: n/a
I am writing a program to store stuff to xml using the storeToXML method
but I can;t get it to compile here it is; any ideas?


import java.io.*;

import java.util.*;

public class XmlWrite {

public static void main(String args[]) throws Exception {

try {

Properties props = new Properties();

props.setProperty("something", "bla");

props.setProperty("stuff", "brown and black");

props.setProperty("morestuff", "me");

props.setProperty("enablepassword", "yes");

props.setProperty("answer", "null");

String OperatingSystem = System.getProperty("user.home") +"\\";
FileOutputStream xmlwrite =
new FileOutputStream(OperatingSystem + "config.xml");

props.java.util.Properties.storeToXML(xmlwrite, "config");

xmlwrite.close();
}

// if writing to the specified output stream results in an
IOException

catch (IOException e) {

//Print system error

System.err.println("An Error Occured While Writing To The
File");
}

// if os is null.

catch (NullPointerException e) {

//Print system error

System.err.println("OS Value is Null");

}

}

}
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
1. "props.java.util.Properties.storeToXML(xmlwrit e, "config")" does not make
any sense - not to the compiler, not to myself.

2. NullPointerException should never be caught. Instead, your code should
check for null values and _prevent_ the NPE from ever happening.

3. If you ask for help in debugging code, provide the full list of the
compiler errors, as generated by the compiler. Just saying "is does not
compile" won't get you any help.

"Gary Redmond" <gr@iol.ie> wrote in message
news:KH*******************@news.indigo.ie...
I am writing a program to store stuff to xml using the storeToXML method
but I can;t get it to compile here it is; any ideas?


import java.io.*;

import java.util.*;

public class XmlWrite {

public static void main(String args[]) throws Exception {

try {

Properties props = new Properties();

props.setProperty("something", "bla");

props.setProperty("stuff", "brown and black");

props.setProperty("morestuff", "me");

props.setProperty("enablepassword", "yes");

props.setProperty("answer", "null");

String OperatingSystem = System.getProperty("user.home") +"\\";

FileOutputStream xmlwrite =
new FileOutputStream(OperatingSystem + "config.xml");

props.java.util.Properties.storeToXML(xmlwrite, "config");

xmlwrite.close();
}

// if writing to the specified output stream results in an
IOException

catch (IOException e) {

//Print system error

System.err.println("An Error Occured While Writing To The
File");
}

// if os is null.

catch (NullPointerException e) {

//Print system error

System.err.println("OS Value is Null");

}

}

}

Jul 17 '05 #2

P: n/a
storeToXML is Java 5.0. You have to compile it with -source 1.5 (I think).
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.