PDA

View Full Version : [Resolved] Javac Problem




Th3Rabbit
Mar 7, 2013, 10:27 AM
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



ArtOfWarfare
Mar 7, 2013, 11:15 AM
Do you have an

include <your package name here>

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

Th3Rabbit
Mar 7, 2013, 11:30 AM
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.

chown33
Mar 7, 2013, 11:49 AM
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.

Th3Rabbit
Mar 7, 2013, 11:57 AM
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.

chown33
Mar 7, 2013, 12:10 PM
Thanks for posting the code. It clarified a lot.

First, I see this:
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.

Th3Rabbit
Mar 7, 2013, 12:15 PM
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.

chown33
Mar 7, 2013, 12:53 PM
So, problem resolved (http://forums.macrumors.com/showpost.php?p=11874380)?

Th3Rabbit
Mar 7, 2013, 02:31 PM
Thanks was looking for that.

elppa
Mar 7, 2013, 05:30 PM
F*$% Netbeans... I'm more of a C programmer and I'm learning java

Don't take Netbeans name in vain :mad:

When you have written a bit more Java, you will learn to like it very much.