Void invalid type Error in Java.?
-
I'm writing a program in Java that would parse and XML file, save it a database table and then simply print the lines out. I'm a totaly new to Java so my code could seem a little stupid. I am not sure if the program will work. when I was declearing a new method (addPoint) I kept receivng error saying that void is invalid type. I also can;t figure our how to move that method out from the main class. Any ideas how to mage this programm work? Here's the code: package db; import java.io.File; import java.sql.DriverManager; import org.w3c.dom.*; import java.sql.*; import javax.xml.parsers.DocumentBuilderFactory… import javax.xml.parsers.DocumentBuilder; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class db{ public static void main (String argv []){ try { double x; double y; DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse (new File("book.xml")); // normalize text representation doc.getDocumentElement ().normalize (); System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName()); ////////////////////////////////////////… Element root = doc.getDocumentElement(); NodeList points = root.getElementsByTagName("points"); points.getLength(); Node pointNode = points.item(0); 035 Element pointElement = (Element)pointNode; 036 // System.out.print(pointElement.getAttribu… 037 038 class PointElement extends db{ 039 double getX() 040 { 041 return Double.valueOf("x"); 042 } 043 044 } // java.lang.Object.toString(); 051 //import java.sql.*; 052 java.lang.Object.class.toString(); 053 Class.forName("org.postgresql.JDBC"); 054 Connection conn = DriverManager.getConnection("jdbc:postgr… 055 Statement stmt = conn.createStatement(); 056 stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Point (x float, y float)"); 057 stmt.executeUpdate("INSERT INTO Point (+x+ , +y+) "); 058 059 public void addPoint((double x , double y) ) 060 { 061 062 063 stmt.executeUpdate("INSERT INTO Point ("+x+" ,"+ y+") "); 064 } 065 066 067 068 ResultSet rs = stmt.executeQuery("SELECT * FROM Point"); 069 070 while (rs.next()) 071 { 072 x = rs.getDouble("x"); 073 y = rs.getDouble("y"); 074 075 } 076 077 rs.close(); 078 stmt.close(); 079 080 081 082 }catch (SAXParseException err) { 083 System.out.println ("** Parsing error" + ", line " 084 + err.getLineNumber () + ", uri " + err.getSystemId ()); 085 System.out.println(" " + err.getMessage ()); 086 087 }catch (SAXException e) { 088 Exception x = e.getException (); 089 ((x == null) ? e : x).printStackTrace (); 090 091 }catch (Throwable t) { 092 t.printStackTrace (); 093 } 094 //System.exit (0); 095 096 } 097 098 // private static void addPoints(double x, double y) { 099 // TODO Auto-generated method stub 100 101 }//
-
Answer:
Your method declaration has double parentheses. Remove the outer parentheses first.
sende at Yahoo! Answers Visit the source
Related Q & A:
- How to delete file that has invalid name?Best solution by Super User
- How to get actual return type of a generic static method in Java?Best solution by stackoverflow.com
- Is it true that space is mostly an empty void?Best solution by Yahoo! Answers
- Why does employment agency in Canada ask to bring Bank Deposit /Void Cheque for registering in their agency?Best solution by Yahoo! Answers
- How to send a group email if one or more of the email addresses are invalid?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.