DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Location
    Finland
    Posts
    10

    Java writing to xml Simple problem?(code included)

    Here is my problem, in my Java applet i got this textfield(txtNormalHours) and button(xml).
    When I press this button program should create file foo.xml, but nothing happens, no errors.
    Here is the funny part without that button code works fine and foo.xml is created so I think there is something wrong in my main program code?

    I cannot figure what´s wrong.... If someone could tell me what to do.

    Offcourse if there is easier way to write in to xml file please tell.


    main program code:
    Code:
      void button_actionPerformed(ActionEvent e) {
     if(e.getActionCommand().equals("xml"))
     
     {
       String norm = txtNormalHours1.getText(); //get information from textfield
        FOO f1 = new FOO();
        f1.setFoo(norm);
      try {
    
       
         FooHelper.write(f1, "foo.xml");
    
        } catch (Exception ex)
            { ex.printStackTrace();
                    }
    
     }
      }
    FooHelper code:
    Code:
    package simple;
    
    import java.beans.XMLEncoder;
    import java.beans.XMLDecoder;
    import java.io.*;
    
    public class FooHelper {
        public static void write(FOO f, String filename) throws Exception{
            XMLEncoder encoder =
               new XMLEncoder(
                  new BufferedOutputStream(
                    new FileOutputStream(filename)));
            encoder.writeObject(f);
            encoder.close();
        }
    
    
    }
    FOO code:
    Code:
    package simple;
    
    public class FOO {
       private String foo ;
    
       public void setFoo(String s) {
         foo = s;
       }
    
       public String getFoo() {
         return foo;
       }
    }

  2. #2
    Join Date
    Feb 2004
    Posts
    808

    Re: Java writing to xml Simple problem?(code included)

    Originally posted by hiisikukko
    my Java applet ... should create file foo.xml, but nothing happens, no errors.
    applets cannot create files..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Feb 2004
    Posts
    808
    by the way, are you sure you even set the actionCommand string of the button?
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links