Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > importing for package

Reply
Thread Tools

importing for package

 
 
Javabean
Guest
Posts: n/a
 
      03-01-2006
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.


 
Reply With Quote
 
 
 
 
Javabean
Guest
Posts: n/a
 
      03-01-2006
> 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



 
Reply With Quote
 
 
 
 
Javabean
Guest
Posts: n/a
 
      03-01-2006
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.


 
Reply With Quote
 
Owen Jacobson
Guest
Posts: n/a
 
      03-01-2006
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

 
Reply With Quote
 
jussij@zeusedit.com
Guest
Posts: n/a
 
      03-02-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing package in eclipse plug in maverick Java 0 07-17-2006 03:38 PM
Importing Package through Jar in JCreator Parameter Names problem Alex Java 0 02-20-2006 05:19 AM
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM
Importing a package and looping through modules in the package Dave Python 2 02-10-2004 08:14 PM
importing classs without package in JSP ? mhk Java 1 11-28-2003 11:46 PM



Advertisments