CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    33

    imho strange error with arrays:

    Hi !
    I have a canvas-derived class used in an applet.
    I have declared a variable global to this class:

    public
    class LView1
    extends Canvas
    {
    private int[][] laby = new int[75][75];
    private int labSize;
    private Image screenImageBuffer;
    private Graphics screen;
    private Image[] stoneImageBuffer = new Image[stoneCount];
    ....




    In the constructor, I define this Array:

    public
    LView1()
    {
    super();
    this.setSize(300,300);

    for (int i=0;i<30;i++)
    {
    for (int j=0;j<30;j++)
    {
    laby[i][j] = 1;
    }
    }

    this.repaint();
    }




    When I try to access any index of this Array, at this point everythings ok.
    But later, in another procedure, I get an
    ArrayIndexOutOfBoundsException,
    as soon as i or j become larger than 29.

    public
    boolean updateView()
    {
    screenImageBuffer = createImage(300,300);
    screen = screenImageBuffer.getGraphics();

    for (int i=0;i<labSize;i++)
    {
    for (int j=0;j<labSize;j++)
    {
    drawSingleStone:{
    for (int playerNr=0;playerNr<4;playerNr++)
    {
    if ((i == player[playerNr].x)&&(j == player[playerNr].y))
    {
    screen.drawImage(stoneImageBuffer[11+playerNr],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
    break drawSingleStone;
    }
    }
    screen.drawImage(stoneImageBuffer[laby[i][j]],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
    }
    }
    }
    this.repaint();
    return true;
    }
    }




    Any suggestions?

    cu
    Skippy


  2. #2
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    249

    Re: imho strange error with arrays:

    I think the problem might be because you're not specifing both indexes of the array. Try using

    laby[i][j] = 1; instead of laby[j] = 1;

    -------------------------------------------
    weaver
    icq# 64665116
    Please rate this post.
    http://weaver.x7.htmlplanet.com

  3. #3
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    33

    Re: imho strange error with arrays:

    Hi !
    Yes absolutely good point. But there is a
    thing to say : I do use laby<i>[j],
    but if you write that here with both brackets like this ( [ ), the <i> is interpreted as
    bold, I'm sorry, I thought between the
    <javacode> tags I could write what I want.
    I'm sorry for that.

    cya
    Skippy


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured