This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I have a directory called test and it has these two files in them.
1) A.java and 2) B.java
The code for A.java
The code for B.java
The A.Class file is in the directory test. When i try compiling B.java[while being in the directory test] it is not able to resolve A(compile time error). Could somebody tell me what is happening? Where am i going wrong?
For the instance, B is stored within the same package as A (Test). However since its in the same package, the error was called. From A.java, remove the package Test and run the program. It should not show any error.
Note that you have the package structure and directory structure wrong.
The directory structure must match the package structure. You have a class A in package test, which is in directory 'test'; your class B is not in package test, yet you have it in the same directory as class A.
You need to move B.java up one directory (it must not be in the 'test' directory, but one level up), or you must put class B in package test also (add a statement "package test;" to B.java and remove the "import test.A;").