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

2020/2/11

World Constructor Threw in an Exception - Help

DaRafster DaRafster

2020/2/11

#
Terminal mentions a problem with the method "create tree" Please note I am a beginner in coding What's wrong with my code?
  public void createTree(int bottomLeftX, int bottomLeftY)
    {
        int change = 80;
        int change1 = 28;
        int change2 = 2;
        int change3 = 5;
        int change4 = 35;
        
        int[] xValues = {bottomLeftX, bottomLeftX, bottomLeftX + change, bottomLeftX + change, bottomLeftX + 
                         change - change1, bottomLeftX + change - change1, bottomLeftX + change - change2};
        
        int[] yValues = {bottomLeftY, bottomLeftY - change + change3, bottomLeftY - change + change3, bottomLeftY 
                         - change + change4, bottomLeftY - change + change4, bottomLeftY + change - change4, 
                         bottomLeftY + change - change4, bottomLeftY + change + change3};
        int points = 8;
        
        myImage.setColor(new Color(34,177,76));
        myImage.fillPolygon(xValues,yValues,points);
        
        myImage.setColor(Color.BLACK);
        myImage.drawPolygon(xValues,yValues,points);
        
    }
danpost danpost

2020/2/11

#
Your xValues array on line 9 only has 7 elements. This may not be what caused the exception, however. What type of exception was thrown? You should copy terminal output and post it in your discussion.
DaRafster DaRafster

2020/2/11

#
That was it, I didn't notice I missed one value within the xValues array. Many thanks
You need to login to post a reply.