Razz
Razz

Reputation: 33

Error: Package doesn't exists when importing a user defined package

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

Answers (3)

Manish Doshi
Manish Doshi

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

Shahrzad
Shahrzad

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

Joni
Joni

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

Related Questions