aspose file tools*
The moose likes Beginning Java and the fly likes package not exists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package not exists" Watch "package not exists" New topic
Author

package not exists

deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
in my pc, userdefined packages that i created,are not imported.
when i import them in a java file.it shows
p1 package not exists

i think it is due to the path problem

i already create path-c:\\program files\java\jdk1.6.0\bin;
can anyone help me.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
Note that PATH and CLASSPATH are two different and unrelated concepts. All libraries used by your code need to be present in the CLASSPATH during compilation and runtime.


Ping & DNS - my free Android networking tools app
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
i know these are different
i already set the classpath
but it says p1 does not exists
Doug Braidwood
Ranch Hand

Joined: Apr 04, 2010
Posts: 42
It might be useful to see what directory you are in when you do your compilation and exactly what command you issue to do the compile

This will be javac......


SCJP, SCWCD
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
not understand
the exact directory are as follows
p1 package is in c:\new folder
java file is in c:\new folder
i compile it as
c:\>new folder>javac abc.java
error:-p1 package not exists

now tell me what are the changes i will have to do
Doug Braidwood
Ranch Hand

Joined: Apr 04, 2010
Posts: 42
so the file abc.java exists in the folder c:\new folder ?

what is p1 package? is the file abc.java declared with first line
package p1;

in which case it should be in the folder
c:\new folder\p1
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
in abc file p1 package is imported
this package is created in check.java file which is also in c:\new folder
when i compile abc.java it shows p1 not exists
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14342
    
  22

You have to be careful and pay attention to the details. Instead of randomly trying things out, make sure you understand what you're doing, carefully read the error messages you get and make sure you understand them. Understand how your classpath needs to be set.

See Creating and Using Packages in Sun's Java Tutorials.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
jasper

if you cannot solve the problem then no post reply
when i said already that path and classpath already set
and i also known how to create and use packages
then how can you say that



you said that i have no idea about creaing and importing packages and gave me link for learning them

when i said all files even with names
also show folder name
then no need to give suggestion
only tell me where i did the mistake


you said that read carefully the error
i declared again and again that error is package not exists

now i want to find why it shows package not exists
and how can i remove it
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

amrita singhal,
thoda shaanti rakh
yahan aise rude reply kyon de rahi ho ?

----------------
english translation:
keep your calm
why are you giving a rude reply here ?
----------------

You need to ease up friend. we are all here to help you.

As rightly stated by Jesper Young, you do need to stop trying things randomly.



Also check the source code to see if there is any line such as:



if there is, then the program should be in a folder called p1
you can also try your program without the package line to use the default package.


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
problem is for using my created packages
for default package no problem
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14342
    
  22

Here are some tips.

If you create a class which is in a package p1, you must have a package p1; statement in the source code file, and the source code file should be in a directory named p1.

You should compile the file from the base directory (the directory that contains the directory p1), like this:

C:\New Folder> javac p1\MyClass.java

You should run the class from the base directory, like this:

C:\New Folder> java p1.MyClass

If you have another class in another package that uses p1.MyClass, you must import the class with a statement like: import p1.MyClass;, and you must make sure that the base directory of p1 is in the classpath.

If you don't set up the classpath correctly, you will get a "package does not exist" error.
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
you must make sure that the base directory of p1 is in the classpath.

what is base directory of p1
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

amrita singhal wrote:you must make sure that the base directory of p1 is in the classpath.

what is base directory of p1


in the given example,
C:\New Folder is the base directory for p1.
if p1 was in d:\SomeCode\test

then the base directory would have been that,
in simple words, p1's parent is its base directory.
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41


amrita can you send the piece of code that you have.......


I have some code for you..........


//abc.java
package p1;
public class abc
{}


//bc.java
import p1.abc;
class bc

{

abc a;
}



both are in same directory i.e. e:\rathore



now try these commnds



>javac -d . abc.java


and then

>javac bc.java


it will compile .


Thanks

Living is easy with your eyes closed.....
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186

thanks for reply
now tell me base directory of p1 is in classpath
what does it mean
here
base dir of p1 is c:\new folder
classpath is C:\Program Files\Java\jdk1.6.0\lib\tools.jar;C:\Program Files\Java\jre1.6.0\lib\j2ee.jar
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
inder
i have written the same code as you give and also compile with same commands
i think there is no error in code and compilation
there is some mistakes of classpath adjustment
so tell me what is that?
i gave classpath in previous reply
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41
HI
AMRITA
as per your reply it seems your classpath is not set correctly .....
set your classpath as "C:\new folder";
classpath is the path from where the classloader will search your classes or packages


deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
ok
supoose i set classpath as c:\new folder
so whenever i made any program in java
it is compulsary to save file in c:\new folder
correct?
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41
you can set multiple classpath...........
it is not necesssary to save in C:\new folder;
it is your choice from where you want to save
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14342
    
  22

Some useful links:

Setting the classpath
Managing the Java classpath
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
i have set classpath already from
my computer->properties
now i set it in dos as
set classpath= .;d:\>

now my question is
previously set path is removed automatically becoz we set again
or
previously set path also remain and new path is added with the previous one
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41
the classpath set from the command prompt is temporary, it doesn't overwrite the classpath set from control panel.
your temporary and permanent both remains as your classpath
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

set classpath = .;%classpath%;c:\someCrap\;

meaning append(and prepend) the current value of classpath with some more stuff.

deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
okay
now there is no error about my created package becoz i set
set classpath=.;c:\new folder\;
but now it shows
error in built in packages of javax
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
means it removed the classpath that i set through my computer->properties
when i want to see classpath
i typed in dos as
set classpath
then it shows only that path which i set in dos not shows the path (set in my computer)
is it means it overwrites the previously set path for that particular time.?
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

salvin francis wrote:set classpath = .;%classpath%;c:\someCrap\;

meaning append(and prepend) the current value of classpath with some more stuff.



every time you use the set command in dos, the previous value is overridden.
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
i know that previos which is created in dos is removed
but the path set in my computer->properties can also removed for that time
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
THANK YOU all of you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package not exists