Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java Compiling problem

  • 19-03-2002 3:58pm
    #1
    Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭


    I have a problem at home with compiling programs in java where I am trying to create an object of another class, such as in the following example:
    class CDTest
    {
    	public static void main(String[] args)
    	{
    		CompactDisc cd1 = new CompactDisc();
    	}
    }
    

    The outputted error is:

    C:\My Documents\CDTest.java:5: cannot resolve symbol
    symbol : class CompactDisc
    location: class CDTest
    CompactDisc cd1 = new CompactDisc();
    ^
    C:\My Documents\CDTest.java:5: cannot resolve symbol
    symbol : class CompactDisc
    location: class CDTest
    CompactDisc cd1 = new CompactDisc();
    ^
    2 errors

    Yes the filename is correct and yes they are in the same directory and yes I have tried it on another computer and it compiled nicely. What is the story ??


Comments

  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    Originally posted by Slaanesh
    I have a problem at home with compiling programs in java where I am trying to create an object of another class, such as in the following example:
    <-snip->

    Yes the filename is correct and yes they are in the same directory and yes I have tried it on another computer and it compiled nicely. What is the story ??

    Right, it's a silly problem with java on windows. You're probably using jdk or something.. anyway just simply put the class file that holds the compactdisk method into the same folder as the program you are trying to compile and it should work. hope this helps kthnx!

    sjones


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    Are both files in the same directory? If so try adding a -classpath %CLASSPATH%;. when compiling or -classpath $CLASSPATH:. under unix


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    What Lynchie said. Put the ".\" into the classpath or "." so that it can find the classes in the current directory (where you may be running it from.

    It's the only obvious thing without seeing the rest of the code.


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    I'll try it when I get home.

    Thanks,

    Slaan


  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    textpad is good at stopping this mularky, and it automatically setups the JDK to work aswell (if you've installed it right)


  • Advertisement
  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    AFAIK the current directory is implicitly added to the CLASSPATH in JDK versions 1.2 and above. In the earlier versions you had to add it yourself, this might be the reason it compiled ok on one computer. Of course i could be all wrong :)

    If I ever get this problem I just use "javac *.java", or you could put together a little Ant buildfile that can be used for any small project. That way you'll never see this problem ever again.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    actually now that I think of it, he would of also had to of compiled the other file first, or use "-sourcepath" argument in javac in order for it to compile.


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    Actually,

    I just pointed the classpath to the directory that I was working in, is there a way to point to the 'Working Directory' because I don't want to be changing the class directory all the times I want to compile multiple classes.

    Slaanesh.


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    Adding -classpath %CLASSPATH%;. will always add the current working directory to the classpath. The same goes with the sourcepath too.


Advertisement