Results 1 to 7 of 7
  1. #1
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default What in the heck is wrong??

    Java Code:
             for (int i=0;i<iii;i++) {
                System.out.println(i+"."+iii);
                for (int h=0;h<hhh;h++) {
                    spaces[i][h]=new Space();
                    spaces[i][h].paint();
                    System.out.println(i+","+h);
                }
            }
            System.out.println("hello");
    This code is in a constructor. iii=7,hhh=7. It never gets to the hello code.

    On average, it gets this far:
    0.7
    0,0
    0,1
    0,2
    0,3
    0,4
    0,5
    Although it has gotten up to around 1,4

    I am utterly confused. Any help is appreciated.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: What in the heck is wrong??

    Well, comment out the spaces assignment and see if it iterates correctly. If it does, then there is a problem in Space and possible paint(). Also, are you certain hhh = 7? What does paint() do? What does the Spaces constructor/class look like?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: What in the heck is wrong??

    Okay, the problem is with the Space constructor (should've checked that earlier, sorry). I commented out those two lines, and it works, but when I put the constructor back in, it breaks. Here is the code for the Space constructor:
    Java Code:
        public Space() {
            roadW=true;
            roadS=false;
            roadN=false;
            roadE=false;
            townT="none";
            img=new BufferedImage(100,100,BufferedImage.TYPE_4BYTE_ABGR);
            g2=img.createGraphics();
            g2.setBackground(new Color(0,0,0,0));
            setImages();
        }
    
    public void setImages() {
            try {
                road=ImageIO.read(getClass().getResource("/beginning/pic/road.png"));
            } catch (IOException e) {
            }
            try {
                chin=ImageIO.read(getClass().getResource("/beginning/pic/hutStraw.png"));
            } catch (IOException e) {
            }
            try {
                euro=ImageIO.read(getClass().getResource("/beginning/pic/hutStraw.png"));
            } catch (IOException e) {
            }
            try {
                afri=ImageIO.read(getClass().getResource("/beginning/pic/hutStraw.png"));
            } catch (IOException e) {
            }
        }

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: What in the heck is wrong??

    I can't tell from this. I would need to see the Space class. Did it work with only paint commented out?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: What in the heck is wrong??

    That is the Space class. And you are correct, with only the paint method commented out, it doesn't work.

    Might it be connected to calling a method from the constructor? (I'm not at home, so I can't test that out at the moment.)

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: What in the heck is wrong??

    That can't be all the Space class. You assign instances of Space to the 2d array and then call a paint() method which isn't shown. And there are numerous instance variables which are used but not declared. All you showed was a constructor and setImages() method.

    In any event you are ignoring your IOExceptions. You should print out the stack trace for each one. Also, every time you invoke your constructor, you read in the image. But since the images don't change, you are repeating work that need not be repeated. Why not check to ensure the images have not already been read once and if them have then pass back a reference to them. This latter suggestion may not be related to your problem but it will make your app more efficient.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: What in the heck is wrong??

    Oh yeah. Really sorry I forgot about that. Will definitely try those suggestions and if they don't work I will post the rest of the code. (When I get a chance).

    EDIT: That fixed it (somehow). Thanks for your help.
    Last edited by Prime624; 05-19-2013 at 07:21 PM.

Similar Threads

  1. Where the HECK do I find a partner in java programming SKYPE BUDDY
    By Wesley.laferriere in forum Forum Lobby
    Replies: 1
    Last Post: 02-07-2013, 04:48 AM
  2. What the heck is going on?
    By Technubee in forum New To Java
    Replies: 5
    Last Post: 10-09-2011, 12:49 PM
  3. NullPointerException is heck of a problem!
    By amanrv in forum New To Java
    Replies: 3
    Last Post: 07-18-2011, 08:52 AM
  4. What the heck is wrong with this code.
    By eLancaster in forum New To Java
    Replies: 12
    Last Post: 06-08-2011, 07:09 AM
  5. What the heck??? Need urgent help!
    By Julian in forum New To Java
    Replies: 4
    Last Post: 05-07-2011, 02:26 PM

Posting Permissions

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