Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

CLASSPATH & Package/Import

  Asked By: Kenneth    Date: Aug 18    Category: Java    Views: 1332
  

i m new to java, the thing that is troubling me is that i can't
import my paskage file. What i did is that i made a sub directory as:

e:\jdk1.4\bin\JWork\mypackages

JWork is the subdirectory where i keep my files and in mypackages i
put the files to be imported. But i can't import files from the
mypackages.
What i write for packages is :

package JWork.mypackages;

and in the other file i write :

import JWork.mypackages.Dessert;

where Dessert is the package name. The error message that i received
is :

package JWork.packages does not exist

I think it could be the problem with the CLASSPATH, that the class
path is not properly set but i suppose that installation for the 1.4
should automatically set the CLASSPATH. Well i don't know how to set
the CLASSPATH if it is the problem with CLASSPATH.

Well what ever the case is i will be greatful to u in help me to
sought the problem

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Keith Marshall     Answered On: Aug 18

with reference to my perivoius mail:

i added the CLASSPATH, the problem  is still not solved this time the error  is:

------------------------------------------------
E:\jdk1.4\bin\JWork\Dinner.java:14: cannot access Dessert
bad class file: E:\JDK1.4\bin\JWork\myPackages\Dessert.class
class file  contains wrong class: mypackages.Dessert
Please remove or make sure it appears in the correct
subdirectory of the classpath.
Dessert x = new Dessert();
^
1 error

Tool completed with exit code 1
------------------------------------------------
and here is the code
------------------------------------------------
//Placed in E:\JDK1.4\bin\JWork\myPackages
//: Dessert.Java
//Creates a library
package mypackages;

public class Dessert
{
public Dessert()
{
System.out.println("Dessert constructor");
}

void foo()
{
System.out.println("foo");
}
}
------------------------------------------------
//Placed in E:\JDK1.4\bin\JWork
//: Dinner.java
//Uses the my own library
import myPackages.Dessert;

public class Dinner
{
public void Dinner()
{
System.out.println("Dinner constructor");
}

public static void main (String[] args)
{
Dessert x = new Dessert();
}
}
------------------------------------------------
and here is the classpath
E:\JDK1.4\bin\JWork;E:\JDK1.4\bin\JWork\myPackages
------------------------------------------------
i will be greatfull to u in helping to solve my problem

 
Didn't find what you were looking for? Find more on CLASSPATH & Package/Import Or get search suggestion and latest updates.




Tagged: