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

Java problem

Options
  • 18-04-2006 4:24pm
    #1
    Closed Accounts Posts: 521 ✭✭✭


    This is just a quick example but shows my problem:
    
    class go{
    public static void main(String args[]){
    lala la = new lala();
    System.out.println(la.add(3,4));
    }
    }
    
    
    class lala{
    public int add(int i, int t){
    return i+t;
    }
    }
    
    
    Both lala & go are in seperate files. Same directory.

    Compiling "lala" is no problem.
    After doing so, I compile "go" and get an error:

    C:\h\go.java:4: cannot resolve symbol
    symbol : class lala
    location: class go
    lala la = new lala();

    I figure that go can not see the lala class as stated above....
    I dont know how to fix it.

    Any help please?


Comments

  • Registered Users Posts: 6,236 ✭✭✭Idleater


    I copied your example. It compiles and runs...
    C:\code\working directory\test>javac go.java
    
    C:\code\working directory\test>java go
    7
    
    


  • Closed Accounts Posts: 888 ✭✭✭themole


    try moving the lala class above the main class


  • Closed Accounts Posts: 521 ✭✭✭EOA_Mushy


    I am assuming this has some thing to do with classpath....

    But thats as far as my knowledge goes in that area.
    The main method, on my computer, cant seem to find ANY other class that need to be used.

    In enviroment variables the only entry to the class path is "C:\j2sdk1.4.2_11\jre\lib\ext\mysql-connector-java-5.0.0-beta-bin;" due to the fact i need to connect to a mysql database later.

    When i put the above line in, the problem started... (Takeing the line back out doesnt work either... not that i want it to)


  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    Alternatively, you have not explained the setup fully (i.e. lala is in a seperate file,and that is no the only error):
    return i+t);
    Remove ")" as lala is not being compiled, and not found...


  • Closed Accounts Posts: 521 ✭✭✭EOA_Mushy


    Opps... the ")" isnt there. (will edit original post)


  • Advertisement
  • Closed Accounts Posts: 888 ✭✭✭themole


    if the two classes are in the same file then there should be no classpath issues.

    however if they are in different files then lala will have to be compiled already and its location will have to be on the classpath.

    this can be done be setting the classpath environmental variable or passing the -classpath arguement when compiling/running the program


  • Closed Accounts Posts: 521 ✭✭✭EOA_Mushy


    I got the problem fixed up.

    Solution: I put the reference to connetor j into the "path" in enviroment variables instead of "classpath" and left every thing else alone.

    I now have no idea why every one on the net was talking about the classpath. That turned out to be the problem in my instance.

    Any how, thanks for the advice every one :)


Advertisement