Search code examples
javajava-7javacimporterror

How to share symbols in java?


I have two java programs (classes), both in a directory called java_weirdness.

Here they are below :

MyClass

package java_weirdness;
public class MyClass{
    public int num;
    public MyClass(int initialNum) {
        num = initialNum;
    }
}

MyLauncher

package java_weirdness;

public class MyLauncher {

    public static void main(String[] args) {
        MyClass new_member = new MyClass(3);
    }
}

When I compile MyLauncher.java, I get the following errors, even though I clearly imported it:

MyLauncher.java:7: error: cannot find symbol
        MyClass new_member = new MyClass(3);
        ^
  symbol:   class MyClass
  location: class MyLauncher
MyLauncher.java:7: error: cannot find symbol
        MyClass new_member = new MyClass(3);
                                 ^
  symbol:   class MyClass
  location: class MyLauncher
2 errors

What is the proper way to access MyClass while in MyLauncher? Thank you.


Solution

  • go up one directory then do

    javac java_weirdness/*.java
    

    and after

    java java_weirdness.MyLauncher
    

    form more info look here

    PS: we're too much IDE dependent xD