Results 1 to 5 of 5

Thread: Default constructor cannot handle Ioexception type

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default Default constructor cannot handle Ioexception type

    So more Java trouble here -.-

    When I try to initialize a game object

    java Code:
    GameObject spike = new GameObject(40, 40, new TBox(40, 40, 80, 80), 10, 5000, "spike.png");

    I get this error:



    Here is what my game object class looks like

    java Code:
    package main;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;

     class GameObject {
       
        private final int x, y;
        private final TBox currentBounds;
        private final int damage, value;
        private final String fileName;
        private final BufferedImage Img;
       
        public GameObject(int x, int y, TBox currentBounds, int damage, int value, String fileName) throws IOException {
            this.x = x;
            this.y = y;
            this.damage = damage;
            this.currentBounds = currentBounds;
            this.value = value;
            this.fileName = fileName;
            this.Img = ImageIO.read(new File(fileName));
        }  
       
    }

    Just spent the last 40 minutes looking for answers all I found was to put super(); after

    java Code:
    public GameObject(int x, int y, TBox currentBounds, int damage, int value, String fileName) throws IOException {

    but I still got the error

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Lol.. Get a better IDE than whatever crap it is you're using.. That has to be one of the worst error messages I've ever read.

    I did however notice that this code is in main's package.. Why is that?

    Just try catch the read.. Otherwise try catch wherever it is you're creating GameObject instances.

    Apparently you have a child class inheriting from this class. You need to handle the exception within the child class's constructor or else make the child class throw the same exception too.
    Last edited by Brandon; 02-27-2014 at 02:08 AM.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Lol.. Get a better IDE than whatever crap it is you're using..
    If you knew the IDE I was using it would only make you mad

    Anyway, when I had try catch before, I get this error:


  4. #4
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    If you knew the IDE I was using it would only make you mad

    Anyway, when I had try catch before, I get this error:


    So then you initialize it in the catch block to null.
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    So then you initialize it in the catch block to null.
    gotcha thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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