• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Cannot resolve symbol

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try giving . (current directory) in your classpath.
 
Glade Wishart
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you - that did work. Do you know why this is the case?
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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".


Because the default classpath is the current directory, and because your problem dissappeared when setting the classpath to "." ; I think you had set a previous classpath which did not include the current directory.


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".


It worked ok for me.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic