Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Method calls/initialization issues

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Method calls/initialization issues

    Hi there,

    First time posting here - wondering if anyone could lend a hand!
    I'm making an import/export of xml - I have the import of xml sorted I'm just trying to finish off the export.
    My export class is called XmlWriter.java


    Inside the class I have an updateFile method to update an xml file as such:
    public void updateFile(Environment environment,Document doc)
    {
     // code
    }

    I then in my main method have
    public static void main(String argv[]){
     
                   //declare new object of class
                  XmlWriter xmlWriter = new XmlWriter();   
     
                   //test testUpdate method
                   //     xmlWriter.testUpdate();
     
                  Environment environment = ;
                  Document doc = ;
     
                   //call method to update
                  xmlWriter.updateFile(environment,doc);
     
                   //call method to export
     
     
           }

    I don't know what to make my variables equal to - eclipse keeps trying to use null but obviously that won't work. The Environment is another class that just contains getters and setters for the 3 different databases (that are in the xml file) and the getter/setter for the environment ID (also in xml file). Any help would be appreciated as I'm confused as to what to set the variables to :S


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Method calls/initialization issues

    What does the updateFile() method do? Shouldn't you already have an Environment and a Document if you're trying to do something with them? Where are they coming from? What types of constructors do they have?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Method calls/initialization issues

    Document doc is only used in documentBuilderFactory to get hold of a document and parse it so it can be edited/updated

    Environment is a class that uses getters/setters that refer to the 'environment' and 'Database' in the xml file

    This is my updateFile method:
    public void updateFile(Environment environment,Document doc)
    {
    //get the tag environment                
    Node env = doc.getElementsByTagName( "environment" ).item(0);
     
     
     
     
    //assign nodelist to env so it gets the child nodes of the environment
                         NodeList list = env.getChildNodes();
                          for (int i2 = 0; i2 < list.getLength();i2++)
                         {
     
                                //go onto the next node
                               Node node = list.item(i2);
     
     //get the elements from environment and then update their values
                                //using setTextContent(" ");
                                if ("URL" .equals(node.getNodeName())){
                                      node.setTextContent( "" );
                               }
    }
    Last edited by AliceH; September 17th, 2014 at 09:44 AM.

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Method calls/initialization issues

    The classes Document and Enviroment, where they written by you? Are they part of some third party library? Or were they written by your instructor / teacher / etc?

    Usually you should simply read the API or the source code of the class you want to use if you want to know which constructor to call.

Similar Threads

  1. [SOLVED] Method calls and output looks a little funny
    By Shadud in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 26th, 2012, 10:47 PM
  2. Method calls and Invocation
    By Akirien in forum Java Theory & Questions
    Replies: 1
    Last Post: August 24th, 2012, 01:37 PM
  3. Problems With Method Calls and Variables
    By connor3452 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 17th, 2012, 05:46 AM
  4. Need help understanding method calls and such
    By hackman2007 in forum Java Theory & Questions
    Replies: 8
    Last Post: July 14th, 2010, 08:18 AM
  5. Any way to map method calls?
    By Swiftslide in forum Collections and Generics
    Replies: 1
    Last Post: September 21st, 2009, 04:37 AM

Tags for this Thread