• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to compile these java files  RSS feed

 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new to java and i developed following code. i am not able to compile these files. i am getting error while compiling second file

C:/Code/foo >javac Person.java
C:/Code/foo >javac Employee.java
Employee.java:2: cannot resolve symbol
symbol : class Person
location: class foo.Employee
public class Employee extends Person
^
1 error

following are code
Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(String name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(int empID) {this.empID=empID;}
}



settings
set JAVA_HOME="C:\JDK1.4";
set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"
 
Sujatha Rangarajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you have to include the import statement
import foo.Person;
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
compile the files from C:\code like this.

C:\Code>javac foo\Person.java
C:\Code>javac foo\Employee.java

Prabhakar
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sujatha Rangarajan:
i think you have to include the import statement
import foo.Person;

No, that is not necessary, because both class Person and class Employee are in the same package foo. You don't need to import classes that are in the same package.

Prabhakar's answer is right - you have to compile it from the directory C:\Code, not from C:\Code\foo.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

you have set your classpath as,

set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"

so do following ,

compile as

javac -d . <classfile1>
java -d . <classfile2>

Make sure that classfile2 depending on classfile1.

Happy compiling...
 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,
it compiled Successfully
 
DeepakKumar Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by KRK Gowda:
i am new to java and i developed following code. i am not able to compile these files. i am getting error while compiling second file

C:/Code/foo >javac Person.java
C:/Code/foo >javac Employee.java
Employee.java:2: cannot resolve symbol
symbol : class Person
location: class foo.Employee
public class Employee extends Person
^
1 error

following are code
Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(String name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(int empID) {this.empID=empID;}
}



settings
set JAVA_HOME="C:\JDK1.4";
set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"
 
DeepakKumar Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by KRK Gowda:
i am new to java and i developed following code. i am not able to compile these files. i am getting error while compiling second file

C:/Code/foo >javac Person.java
C:/Code/foo >javac Employee.java
Employee.java:2: cannot resolve symbol
symbol : class Person
location: class foo.Employee
public class Employee extends Person
^
1 error

following are code
Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(String name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(int empID) {this.empID=empID;}
}



settings
set JAVA_HOME="C:\JDK1.4";
set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"
 
DeepakKumar Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all you should comple the files like this

javac -d . Person.java
javac -d . Employee.java

-d stands for directory and the'.' followed by it represents the path where the files are located to be compiled.So just go through the options and i m sure that it will work.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!