I have created a simple program listed below using two files X.java and TestX.java.
// X.java
public class X
{
private int value;
public void setValue( int value )
{
this.value = value;
}
public int getValue()
{
return value;
}
}
// TestX.java
public class TestX
{
public static void main(
String[] args )
{
X x = new X();
x.setValue( 5 );
System.out.println( x.getValue() );
}
}
I am able to compile X.java but I receive an error when compiling TestX.java. The error is as follows: "cannot resolve symbol" referring to X and X() on line 5. My understanding is that when packages are not used
Java begins by searching the current directory which is where both files exist "C:\X.java and C:\TestX.java".
If I combine the X.java code into the TestX.java file and change the line public class X to class X - TestX.java will compile but when attempting to run TestX.class using java TestX I receive the following error: "Exception in
thread main java.lang.NoClassDefFoundError: X".
If anyone could help I would appreciate it.
Thank you in advance.