Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Unable to use package...why ??? Date: Thu, 27 Oct 2011 07:33:49 -0700 (PDT) Organization: http://groups.google.com Lines: 78 Message-ID: <7180194.1172.1319726029502.JavaMail.geo-discussion-forums@prib32> References: <280344ac-b398-44b3-b775-e84859feb5f0@gy7g2000vbb.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 216.239.45.130 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1319726029 14661 127.0.0.1 (27 Oct 2011 14:33:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 27 Oct 2011 14:33:49 +0000 (UTC) In-Reply-To: <280344ac-b398-44b3-b775-e84859feb5f0@gy7g2000vbb.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=216.239.45.130; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9247 PortisHead wrote: > First I created the file : Getbcard.java > inside the directory : C:\myclasses\exam\test\dok > below is the script : > package exam.test.dok; "myclasses" is the root of the classpath for this class. Directories that match up with packages descend from such a root. > public class Getbcard > { > public void setname() > { > System.out.println("Hello"); > } > } > > then , I compiled it using this command line: > javac Getbcard.java From what directory? Where is your "exam/test/dok/" directory path? ("exam\test\dok" in Windows.) > and got the appropriated .class file: > Getbcard.class In what directory? > Next , I created a new file , named : Showbcard.java in folder : C: > \examples That sounds like a class with no package. Do not mix classes in packages with classes in the "no-package" (the default package, which isn't really a package). Packages have to match with directories, in the normal filesystem approach. If they do not, you are fubared. > below is the script : Not a script. > import exam.test.dok.*; > public class Showbcard > { > public static void main(String[] args) > { > System.out.println("Showbcard"); > Getbcard i = new Getbcard(); > i.setname(); > } > } > > > then , I compiled it using this command line: > javac -cp c:\myclasses Showbcard.java > and got the appropriated .class file: > Showbcard.class In what directory? > Now when I try to execute the file like : > java -cp c:\myclasses Showbcard > > I get the error : Could not find or load main class Showbcard > > What am I doing wrong here ? As mentioned upthread, you left out the package in the class for the "java" command. Note: Do not use the CLASSPATH variable. Stick with the "-jar" or "-cp" options to set classpath. -- Lew