Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Th3Rabbit

macrumors newbie
Original poster
Mar 7, 2013
5
0
Ok so I'm a relatively new programmer in java and I am trying to do some graphical stuff using a library called stdDraw. I have copied the stdDraw.class and the stdDraw.java files into directory of my program but when I use javac inside the directory of the program I get an error of "cannot find symbol". The error refers to javac being unable to find the stdDraw class file but it's there in the programs directory. I've tried -cp and referring it to the path of the program but it still gives me the same error which is extremely frustrating I do the same thing on my linux desktop and it works 100%... Highly annoying is there something idiotic I'm doing which can be pointed out please? Thanks in advance
 
Last edited:
Do you have an

Code:
include <your package name here>

Statement at the top of the file from which you want to access it?
 
Still Not

Yah I tried using include which doesn't work and import which then gives me an error of identifier expected. However on the plus side import did only give me 1 error instead of three so I guess thats on the right track any other suggestions? Thanks by the way.
 
When you get an error, post the error message and the code that caused it. We can't see your screen. We can't debug descriptions. Post your code.

When you describe command lines, like using -cp, give the complete command line you used (copy it from Terminal), exactly as you tried it. Also copy and paste the complete error message.

When you use non-standard classes, like stdDraw, post the URL where you got them, so we know what you're using. Googling stdDraw finds this:
http://introcs.cs.princeton.edu/java/35purple/StdDraw.java.html

Assuming that's what you're using, at least one problem is obvious: Java is case-sensitive. You need to refer to the StdDraw class in your code (the code you haven't posted), not stdDraw.
 
Very well

Code:
package probdraw;

public class Probdraw 
{
	

    public static void main(String[] args) 
    {
		
        int N = Integer.parseInt(args[0]);
        double p = Double.parseDouble(args[1]);
        int r = 5;
        double theta = 2*Math.PI/N;
        StdDraw.setXscale(-r-2, r+2);
        StdDraw.setYscale(-r-2, r+2);
        
        for(int i = 0; i < N; i++)
        {
            StdDraw.point(r*Math.cos(i*theta),r*Math.sin(i*theta));
        }
        
        for(int i = 0; i < N; i++)
        {
            for(int j = i; j < N; j++)
            {
                if(Math.random() < p)
                {
                StdDraw.line(r*Math.cos(i*theta),r*Math.sin(i*theta),r*Math.cos(j*theta),r*Math.sin(j*theta));
                }
            }
        }
    }
}

Error Message:

Probdraw.java:14: error: cannot find symbol
StdDraw.setXscale(-r-2, r+2);
^
symbol: variable StdDraw
location: class Probdraw
Probdraw.java:15: error: cannot find symbol
StdDraw.setYscale(-r-2, r+2);
^
symbol: variable StdDraw
location: class Probdraw
Probdraw.java:19: error: cannot find symbol
StdDraw.point(r*Math.cos(i*theta),r*Math.sin(i*theta));
^
symbol: variable StdDraw
location: class Probdraw
Probdraw.java:28: error: cannot find symbol
StdDraw.line(r*Math.cos(i*theta),r*Math.sin(i*theta),r*Math.cos(j*theta),r*Math.sin(j*theta));
^
symbol: variable StdDraw
location: class Probdraw
4 errors

Command used is using a very basic level of terminal and is most probably wrong: javac -cp . probdraw.java
and tried: javac -cp "." probdraw.java
and tried: javac -cp "~/Desktop/DropBox/Programming/.../StdDraw.class" probdraw.java
and tried: javac -cp ~/Desktop/DropBox/Programming/.../StdDraw.class probdraw.java

where ... isn't what I used I obviously specified it exactly. I do know that java is case sensitive and I used the correct spelling. Also with java it's supposed to pick up the classes in the folder so I shouldn't have to specify anything. My real question is why isn't it doing that? I downloaded the latest JDK and restarted and it's still being extremely aggravating.

----------

Yes that is the Library I was using to do the work. Thanks for the reply.
 
Thanks for posting the code. It clarified a lot.

First, I see this:
Code:
package probdraw;
Are you supposed to be using a package statement, or is that something you added? I'm asking because the StdDraw class (at least the one I linked to) isn't in a package, and the resulting package/non-package relationship creates a problem.

If you remove the package statement, then it should compile, because then StdDraw and Probdraw will both be in the same non-package.

If you were told to use a package statement, then you should ask your instructor for guidance on using the import statement.
 
You Da Bomb

F*$% Netbeans... It added it there by default and I didn't think it would do anything so I left it. I'm more of a C programmer and I'm learning java now which is quite similar but different at the same time. Quite fun though. Sorry about the code I thought it might just be a standard problem where I was supposed to set a preference setting or something. Thanks a lot.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.