Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:52:15+00:00 2026-06-07T18:52:15+00:00

I know it’s been asked before and answered, but i just can’t make it

  • 0

I know it’s been asked before and answered, but i just can’t make it work.

So, my files hierarchy is:

+ Project
  + build.xml
  + save.xml
  + src
  + build

I have the “save” file to save the state of a game in a given instant. It should be easy to overwrite and easy to read to load everything again in the game.

My save() is like this, and it seems to be working:

 public void save(Game game) throws IOException{
    Document doc = DocumentHelper.createDocument();
    doc.add(game.save());
    File save=null;
    save = new File("./save.xml");

    FileWriter writer = new FileWriter(save);
    doc.write( writer);
    writer.close();
}

game.save() is a method in the game that actually does what i want to do. It does it recursively and all, and i know it works fine because i opened the XML file with another program.

So, my problems begins here. My getinfofromxml() method is:

public Game getinfofromxml() throws IOException{
    Game game;
    SAXReader reader = new SAXReader();
    try{
        URL fileWithData=getClass().getResource("./save.xml");
        Document document = reader.read(fileWithData);
        Element alreadySavedGame= document.getRootElement();
        game= getGameSaved(alreadySavedGame);
    }catch(DocumentException ex){
        throw new IOException();
    }
    return game;
} 

My problem is, when try to run it (via ant), no test will pass. I go to eclipse, and i can see that when i try to load the game, it throws Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException.

I’ve tried changing the line URL fileWithData=getClass().getResource("./save.xml"); to URL fileWithData=getClass().getResource("save.xml"); and URL fileWithData=getClass().getResource("../save.xml"); and things like that, but it says always the same.

Any idea?

Thank you for reading

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:52:17+00:00Added an answer on June 7, 2026 at 6:52 pm

    so, if you use getResource() it will try to find your file using the classloader that was used to load that class. this might be (later at least) the jar file your app is packaged in, and i don’t think that’s you’re trying to load your savegame from there 🙂

    i’d load the file the same way you save it:

    URL fileWithData= new File( "save.xml" ).toURI().toURL(); 
    

    (you might have to catch an extra exception)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been asked before , but I still can't understand why
I know that this sort of question has been asked here before, but still
I know this type of question has been asked a lot but none of
I know this has been asked but I am unable to fix it For
I know this has been asked a million times, but I haven't had much
Know this might be rather basic, but I been trying to figure out how
I know you can not set a key value dynamically, but what about the
Anyone know how I can make a login button in Ruby on Rails for
I know there are lots of tools on the net that can make our
I know regex and substrings is a common question on here but i can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.