-3

I wrote this code:

public class CheckerBoard { 

    public static void main(String[] args) {
        // declaration and initialization - How big?
        int N = Integer.parseInt(args[0]);
        StdDraw.setXscale(0, N);
        StdDraw.setYscale(0, N);

        // Draw from lower left, up and across
        // i is the index for the x value.  j is the index for y.
        for (int i = 0; i < N; i++) {
            for (int j = 0; j<N; j++) {
                if ( ((i+j) % 2)==0){ 
                     StdDraw.setPenColor(StdDraw.BLACK);
                else StdDraw.setPenColor(StdDraw.RED);
                StdDraw.filledSquare( 1, 1 , 0.5);
            }
        }

        StdDraw.show();
    }

And it shows in the result:

StdDraw cannot be resolved
at CheckerBoard.main(CheckerBoard.java:15)

I already added the std.lib in the window-preferences- java thing. Does anyone know what the problem here is?

Nivetha T
  • 481
  • 1
  • 3
  • 17
msd
  • 49
  • 1
  • 2
  • 8
  • eclipse is not able to recognize the jar file in your classpath. – Ankur Singhal Jan 29 '15 at 03:28
  • Is it in the `Build Path`? – PM 77-1 Jan 29 '15 at 03:35
  • No it's not. How do I add the library in build path? – msd Jan 29 '15 at 03:37
  • Select the project from 'Package Explorer'. Right click on the project. Select 'Properties' (last one). Select 'Java Build path' (probably third option). Select 'Libraries' (Probably it will be selected as default).If the the Jar file is not in the list, add the jar by clicking 'Add Jars' or 'Add External jars'. Hope it will help you to check. – Saqib Rezwan Jan 29 '15 at 04:10
  • @SaqibRezwan provide that as answer (after validating the info, of course). – Luiggi Mendoza Jan 29 '15 at 04:25
  • Ok :) @Luiggi Mendoza – Saqib Rezwan Jan 29 '15 at 04:30
  • @SaqibRezwan Thanks a bunch! That worked with the library. But now it shows a new error as I try to compile it "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at CheckerBoard.main(CheckerBoard.java:14)" Do you know what this is about? – msd Jan 29 '15 at 04:40
  • @msd that's another problem and should be posted in a different question. But it's simple: you're accessing to an invalid index of the `args` array. Looks like you're not sending any parameter to the execution of your Java program. You can test the app by using `int N = Integer.parseInt("");` and before submitting your homework change it back to `int N = Integer.parseInt(args[0]);` – Luiggi Mendoza Jan 29 '15 at 04:44
  • Yes, I agree with @LuiggiMendoza – Saqib Rezwan Jan 29 '15 at 04:55

1 Answers1

0

Select the project from 'Package Explorer'. Right click on the project. Select 'Properties' (last one). Select 'Java Build path' (probably third option). Select 'Libraries' (Probably it will be selected as default).If the the Jar file is not in the list, add the jar by clicking 'Add Jars' or 'Add External jars'.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Saqib Rezwan
  • 1,382
  • 14
  • 20