• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package not exists

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know these are different
i already set the classpath
but it says p1 does not exists
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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......
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem is for using my created packages
for default package no problem
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you must make sure that the base directory of p1 is in the classpath.

what is base directory of p1
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 .
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some useful links:

Setting the classpath
Managing the Java classpath
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
set classpath = .;%classpath%;c:\someCrap\;

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

 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANK YOU all of you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic