Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

importing for package

Thread view: 
Javabean - 01 Mar 2006 11:45 GMT
Hi all,

I'm trying to understand the concept of packaging which seems relatively
simple and clean, following the directory concept. To test this I've written
two files: 1 which defines a class and puts it inside a package and 1 which
tries to import the class defined in the package.

This is the code for MyClass.java:

package mypackage;

public class MyClass {
public void greeting(){
 System.out.println("Hello!");
}
}

I have saved this file to c:\java\mylib\mypackage. The CLASSPATH variable is
set as follows : CLASSPATH = .;c:\java\mylib

And the code for Exercise2.java (which tries to import the MyClass file):

import mypackage.*;

public class Exercise2 {
public static void main(String[] args){
 MyClass m = new MyClass();
 m.showMe();
}
}

The MyClass class seems to get imported, however I get an error message when
trying to call the showMe() method.

C:\java\test\Exercise2.java:6: cannot find symbol
symbol  : method greeting()
location: class mypackage.MyClass
 m.greeting();
                ^
1 error

Anyone have any idea why this is? The greeting() method is declared as
public inside MyClass so I should have access to it... I also tried defining
a no-arg constructor for MyClass which produces a text message but the text
message was never printed as well (even though the object seems to be
created without errors?!)

Thanks for any input.
Javabean - 01 Mar 2006 11:48 GMT
> And the code for Exercise2.java (which tries to import the MyClass file):
>
[quoted text clipped - 6 lines]
> }
> }

m.showMe() should read: m.greeting(). I made a mistake with copy/pasting the
code. In my code the method names are identical. So this is not the problem
;-)
Javabean - 01 Mar 2006 12:18 GMT
Figured it out myself. For some reason the CLASSPATH variable wouldn't get
propagated to UltraEdit, from which I compile and run the programs. I had to
explicitly give the classpath as an argument to the javac and java commands
to make it work (e.g. java -classpath ".;c:\java\mylib" Exercise2). Still it
boggles me why UltraEdit doesn't seem to use the classpath environment
variable while it works perfectly from the command line prompt.
Owen Jacobson - 01 Mar 2006 15:12 GMT
> Figured it out myself. For some reason the CLASSPATH variable wouldn't get
> propagated to UltraEdit, from which I compile and run the programs. I had to
> explicitly give the classpath as an argument to the javac and java commands
> to make it work (e.g. java -classpath ".;c:\java\mylib" Exercise2). Still it
> boggles me why UltraEdit doesn't seem to use the classpath environment
> variable while it works perfectly from the command line prompt.

Under Windows, the 'SET' command doesn't propagate back to the GUI.  Check
under Control Panel/System/Advanced/Environment Variables instead, then
*restart UltraEdit*.  Windows programs acquire their environment at
startup, and don't receive changes from the outside world.

-Owen
jussij@zeusedit.com - 02 Mar 2006 00:05 GMT
> Still it boggles me why UltraEdit doesn't seem to use the classpath
> environment variable while it works perfectly from the command line
> prompt.

As a test you could create a batch file that looks like this:

 Set classpath

and run this batch file from within UltraEdit. The captured
output should show the current system wide classpath value.

If the classpath displayed above is not complete then you
need to use the control panel to setup the classpath.

Jussi Jumppanen
Author: Zeus for Windows Java IDE
http://www.zeusedit.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.