Results 1 to 2 of 2
  1. #1
    lana is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default problem loading XML file in java applet

    Hello,

    I face a problem loading my XML data file in java applet.
    Here is the applet code:
    Java Code:
    UserList users;
    
    public void init()
    {
            users = new UserList();
            try{
                users.fillList();
            }
            catch(Exception e){
                System.out.println("Could not fill userlist from file!");
                e.getMessage();
            }
    }
    The fillList method in the UserList class:
    public void fillList() throws Exception  
    {
        setUserList(ReadXML.readXML("XMLFile.xml"));
    }
    
    Here is the relevant lines of code from the ReadXML file:
    public static UserList readXML(String fileName) throws ParseException
    {
        parseXmlFile(fileName);
     ... some code here
    }
    
    public static void parseXmlFile(String fileName)
    {
        // get the factory
        DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
        try
        {
            DocumentBuilder builder = factory.newDocumentBuilder();
    
            //Here we do the actual parsing
            //doc = builder.parse(new File(fileName));
            
            doc = builder.parse(this.getClass().getClassLoader().getResourceAsStream(fileName));
        }
        catch(ParserConfigurationException pce) 
        {
            pce.printStackTrace();
        }
        catch(SAXException se) 
        {
            se.printStackTrace();
        }
        catch(IOException ioe) 
        {
            ioe.printStackTrace();
        }
    }
    
    It all works perfectly fine in the application:
         public static void main(String args[]) throws IOException
        {
            
            UserList users = new UserList();
            try{
                users.fillList();
            }
            catch(Exception exc){
                System.out.println("Could not fill userlist from file!");
            }
    ... some code here
    }
    but now i need to switch to applet implementation and this code fails with no error message. there was an access denied problem of writing to the XML file . i could resolve it by creating a permission policy file following this tutorial: Appendix A: Security and Permissions, but it doesn't help to load the file. I am using Windows XP, the xml file attributes are all set to read, write, delete. I am totally confused about what the problem might be. Any help is greatly appreciated. I need to make it work ASAP. Many thanks in advance.

    the policy file i created:
    grant {
    permission java.io.FilePermission
    "C:\\Documents and Settings\\sveta\\source\\Project\\XMLFile.xml", "read, write, delete";
    };

    the command to run:
    appletviewer -J-Djava.security.policy=polfile CalendarApplet.html
    Last edited by Norm; 11-24-2011 at 04:12 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,456
    Rep Power
    25

    Default Re: problem loading XML file in java applet

    code fails with no error message
    If there are no messages in the console then you could try debugging the code by adding printlns to show where the execution flow goes and to show the values of variables as the program executes.
    Maybe that print out would show you where the problem is.

Similar Threads

  1. Java Applet Strange Image Loading Problem
    By 1yuchen in forum Java Applets
    Replies: 36
    Last Post: 01-06-2012, 02:06 AM
  2. Loading Problem Of Java Application
    By Cluster Storm in forum AWT / Swing
    Replies: 6
    Last Post: 06-09-2010, 07:17 PM
  3. Problem loading in a .txt file
    By blkshp1990 in forum New To Java
    Replies: 1
    Last Post: 11-06-2009, 02:48 AM
  4. Replies: 0
    Last Post: 07-29-2008, 01:19 PM
  5. Java Applet loading bar
    By genette in forum Java Applets
    Replies: 2
    Last Post: 12-27-2007, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •