I have two java files in a directory, neither of them are in a package. I want one of them to be able to reference the other. What is the right way to do this?
Currently in Class A, I’m trying to reference class B, and getting this error:
[javac] A.java:11: cannot find symbol
[javac] symbol : constructor B(java.lang.String)
[javac] location: class B
[javac] B b = new B(path);
[javac] ^
Nothing below worked:
- in A, doing “import B;”
- adding “package myPackage;” to both A and B
Thanks!
You didn’t post your code, so my answer may be wrong, but most likely you’re trying to use a constructor in B which uses a string as parameter when there is none defined like that.
Here’s my test:
Looks the same doesn’t?