Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   importing for package (http://www.velocityreviews.com/forums/t150776-importing-for-package.html)

Javabean 03-01-2006 11:45 AM

importing for package
 
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 03-01-2006 11:48 AM

Re: importing for package
 
> 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();
> }
> }


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 03-01-2006 12:18 PM

Re: importing for package
 
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 03-01-2006 03:12 PM

Re: importing for package
 
On Wed, 01 Mar 2006 13:18:51 +0100, Javabean wrote:

> 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 03-02-2006 12:05 AM

Re: importing for package
 
Javabean wrote:

> 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



All times are GMT. The time now is 08:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.