Skip to main content

Not A Statement - Java Error

1 reply [Last post]
Joined: 2012-09-22

I am trying to compile below code in JDK 1.6 but getting an error "Not a statement" in the below line
File file = new File("/data/userfiles/data/conf/dataConfig.xml"); Since this code has been compiled in previous version like 1.3 and 1.4 version.

Can you please tell me what exactly wrong in this because presence of dataConfig.xml need not be checked in the compile time, it has to be checked only during execution.

Kindly provide me a solution , i have to provide this by tomorrow

Source Code

if (loglevel != 0)
// writelog("Retrieving configuration");
File file = new File("/data/userfiles/data/conf/dataConfig.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
NodeList nodeLst = doc.getElementsByTagName("Configuration");
String servername;
Node fstNode = nodeLst.item(0);
Element fstElmnt = (Element)fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("Server");
Element fstNmElmnt = (Element)fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
servername = ((Node)fstNm.item(0)).getNodeValue();

Element sndElmnt = (Element)fstNode;
NodeList sndNmElmntLst = sndElmnt.getElementsByTagName("Log");
Element sndNmElmnt = (Element)sndNmElmntLst.item(0);
NodeList sndNm = sndNmElmnt.getChildNodes();

String nodeval;
Node mynode = (Node)sndNm.item(0);
nodeval = mynode.getNodeValue().trim();
loglevel = Integer.parseInt(nodeval);

sndElmnt = (Element)fstNode;
sndNmElmntLst = sndElmnt.getElementsByTagName("LogPath");
sndNmElmnt = (Element)sndNmElmntLst.item(0);
sndNm = sndNmElmnt.getChildNodes();

mynode = (Node)sndNm.item(0);
logpath = mynode.getNodeValue().trim();
if (loglevel != 0)
writelog("Log Path: " + logpath);
if (loglevel != 0)
writelog("Server : " + ((Node)fstNm.item(0)).getNodeValue());

return servername;

catch (Exception e)
writelog("Error in Get Server IP:" + e.toString());
return ("ERROR");

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2012-09-21

File file = new File(".//data//userfiles//data//conf//dataConfig.xml");
Firstly I think we must have escape character for '/' in path so it's missing from your code and secondly after if condition you should have statement that to be executed when condition is true but your code has commented code.So implement my suggestion and try again.

Joined: 2012-09-28

Why are you defining the variable file inside of an if statement? Since your write log statement is commented out, that is exactly what you are doing. You are also not using the file variable after it is created, which may only be because you are in the middle of writing the code.

If you define the file variable before the if statement it should work.