Results 1 to 6 of 6
  1. #1
    devonfire is offline Member
    Join Date
    May 2014
    Posts
    3
    Rep Power
    0

    Question Java Game export error

    So I am creating a game in Java, the game works fine when I run it in Eclipse but when I export it it does not draw anything on the screen.
    I added a try and catch for nullpointerexceptions but the game does not throw any nullpointerexceptions.
    What is the problem?
    The game seems to be finding all the images & resources since it does not throw any NullPointerExceptions...

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

    Default Re: Java Game export error

    Change the code to catch all exceptions, not just NPE.

    What classes and methods are you using to read in resources? Not all of them react when the file is not found.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Java Game export error

    Java Code:
    catch(Throwable t){
      t.printStackTrace();
    }
    Will catch-all, be it an Exception or an Error.

    The joke about resource loading in Java: its actually pretty badly designed in my opinion. If a resource cannot be loaded null is returned in stead of an exception being thrown. And if you try to paint a null-resource, simply nothing happens. So where normally you can rely on exception handling mechanisms, here specifically you have to do null-checks and toss an exception yourself.

    Apparently the assumption was that a resource not existing is more likely not an exceptional case. I disagree with that.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    devonfire is offline Member
    Join Date
    May 2014
    Posts
    3
    Rep Power
    0

    Default Re: Java Game export error

    Quote Originally Posted by Norm View Post
    Change the code to catch all exceptions, not just NPE.

    What classes and methods are you using to read in resources? Not all of them react when the file is not found.
    I used this: this.sprite = ImageIO.read(this.getClass().getResourceAsStream(s prite));

  5. #5
    devonfire is offline Member
    Join Date
    May 2014
    Posts
    3
    Rep Power
    0

    Default Re: Java Game export error

    Quote Originally Posted by gimbal2 View Post
    Java Code:
    catch(Throwable t){
      t.printStackTrace();
    }
    Will catch-all, be it an Exception or an Error.

    The joke about resource loading in Java: its actually pretty badly designed in my opinion. If a resource cannot be loaded null is returned in stead of an exception being thrown. And if you try to paint a null-resource, simply nothing happens. So where normally you can rely on exception handling mechanisms, here specifically you have to do null-checks and toss an exception yourself.

    Apparently the assumption was that a resource not existing is more likely not an exceptional case. I disagree with that.
    Okay, I'll try this, thx

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Java Game export error

    Quote Originally Posted by devonfire View Post
    I used this: this.sprite = ImageIO.read(this.getClass().getResourceAsStream(s prite));
    That results in an IllegalArgumentException if getResourceAsStream() returns null.

    http://docs.oracle.com/javase/7/docs...InputStream%29

    When in doubt, check the API documentation.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Import and Export Files in Java
    By javalearner in forum Eclipse
    Replies: 7
    Last Post: 11-21-2013, 01:41 PM
  2. Error by export Data from Excel File to MySql database
    By vector_ever in forum Apache POI
    Replies: 6
    Last Post: 08-01-2013, 11:15 PM
  3. error during export, please help me
    By ginger0001 in forum Advanced Java
    Replies: 3
    Last Post: 03-25-2012, 05:12 AM
  4. Error during export
    By ginger0001 in forum New To Java
    Replies: 0
    Last Post: 03-24-2012, 10:41 PM
  5. Export to Java program, applet or c/c++
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:55 AM

Tags for this Thread

Posting Permissions

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