wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Invoking method in packaged class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Invoking method in packaged class" Watch "Invoking method in packaged class" New topic
Author

Invoking method in packaged class

Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
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

Joined: Apr 04, 2009
Posts: 93
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


Brainbench Java 2.0 Fundamentals, J2EE 1.4
http://www.brainbench.com/transcript.jsp?pid=8192792
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
Thank you , it was the asterisk.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoking method in packaged class