Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation problems

 
ven kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having some troubles compiling java source files from command prompt.
I have class1.java and class2.java in package app. So, I created a directory named "app", put "Class1.java" and "Class2.java" in that directory. Class2.java is a simple java program with one method (method2) to print some message on the console when executed. I'm trying to access method 2 of Class2 from Class1. When I try to compile it, it is giving me compilation errors that "Can not resolve symbol Class2". Any help is appreciated.
Thanks
Kumar
 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It mean the jvm can't find class2
have you put "app" directory in the CLASSPATH? or have you define the package name for class1 & class2?
 
Dhamodharan Krishnan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ven Kumar,
From the info that you have given, let me guess that your classes are like this
-----------------------------
package app;
public class Class1
{
Class2 c2;

public Class1()
{
c2 = new Class2();
c2.method2();
}
public static void main()
{
Class1 c1 = new Class1();
}
}
---------------------------------
package app;
public class Class2
{
public Class2
{
}
public void method2()
{
System.out.println("I am method2 speaking!");
}
}
-------------------------------------
Both these classes are in app directory.
Let me assume that you have the Java files in
D:\Dev\app folder
Please go to D:\Dev folder
From D:\Dev, try compiling Class2 first.
Then compile Class1
Then run Class2.
It should work fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic