• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking method in packaged class

 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two classes C:\GBJava\SourceLib\GBTestA.java , C:\GBJava\SourceLib\GBTest.java





It seems odd that the error is GBTest.java:1: package com.hotmail does not exist
The package name is truncated - graemebyers missing.

Change the source to below and all OK - What am I doing wrong ?


Thank you.
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Graeme Byers wrote:Two classes C:\GBJava\SourceLib\GBTestA.java , C:\GBJava\SourceLib\GBTest.java




Please change line

import com.hotmail.graemebyers ;

to

import com.hotmail.graemebyers. GBTestA;
or
import com.hotmail.graemebyers. *;

in the above code and it should work. Also if your app context is in the classpath you don't require this even. Set classpath as

set classpath=.;%classpath%; at dos console


Note: Your class files should be under:
<<AppContext>>\com\hotmail\graemebyers\GBTestA.class
<<AppContext>>\GBTest.class
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Import statements always refer to classes, not to packages. If you want to import all the classes in a package, you use a wildcard to stand in for the class names:

import com.hotmail.graemebyers.*;

Don't use the CLASSPATH environment variable, as recommended above -- there be dragons.

 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you , it was the asterisk.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was about to post this, when I saw you had got an answer. You can have it anyway

**************************************************************************

I presume your two classes are in different files, or they won't compile.
Search this forum for how to compile a class with a package declaration; there are several ways to do it. If you find my first post in this thread, for example, you get links to how to do it.
You will have to compile the classes with a wildcard (*.java), or compile the class with the package declaration first.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic