This site requires JavaScript, please enable it in your browser!
Greenfoot back
Casper
Casper wrote ...

2017/4/22

act() IOException problem

Casper Casper

2017/4/22

#
I'm doing a game. When player gets to the other side of a map, the next map should load. I have a problem with calling a method which loads next map in act() because that method uses BufferedReader and I can't use "throws IOException" in act. Greenfoot keeps writting "act() in MyWorld cannot override act() in greenfoot. World overriden method does not throw java.IOException" If I write act without "throws IOException" greenfoot writes "unreported exception java.io.IOException; must be caught or declared to be thrown"
1
2
3
4
5
public void act() throws IOException{
    if(player.X() > getWidth()){
         loadNextMap();
    }
}
davmac davmac

2017/4/22

#
Catch and handle the exception instead of trying to let it propagate:
1
2
3
4
5
6
7
8
9
10
11
public void act() {
    try {
        if(player.X() > getWidth()){
             loadNextMap();
        }
    }
    catch (IOException ioe) {
        System.out.println("I/O error when trying load to load map");
        Greenfoot.stop();
    }
}
Casper Casper

2017/4/22

#
Thanks man
You need to login to post a reply.