Reputation: 33
I am trying to import a package, but when compiling it shows error like :
Package doesn't exists
I tried the same with a small example, but again the same error is raising. here is the sample code :
D : company
|-salary
Above is the directory structure.
package company.salary;
public class Income
{
private int value;
public int getValue() { return this.value; }
}
package company;
import company.salary.*;
public class Budget
{
public int calculateSavings()
{
return 0;
}
}
Upvotes: 1
Views: 6550
Reputation: 1193
You don't need to import company.salary.*
As it is already inside in Company package.So it is never used.
So your structure should be like this: In Company package there will be another Salary package and Budget.java and in Salary package it will be income.java file.
Budget.Java
package company;
public class Budget
{
public int calculateSavings()
{
return 0;
}
}
Income.java
package company.salary;
public class Income
{
private int value;
public int getValue()
{
return this.value;
}
}
If you don't already know this, you should probably read this: http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html#Understanding
Upvotes: 1
Reputation: 1072
No need to import company.salary.*
it is already inside the company package. Why you don't use eclipse or NetBeans IDE, it will make your task easier, simply write code and let the IDE to make suggestions for your errors.
Upvotes: 1
Reputation: 111219
To compile, go to the root and use paths:
D:\>javac company\Budget.java
The compiler has a slightly peculiar way of looking for source code files, documented here. Alternatively you could add the root to the class path explicitly:
javac -classpath D:\ Budget.java
Upvotes: 1