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 / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

My own java library, like in C++

Thread view: 
jalkadir - 16 Aug 2005 05:13 GMT
I have been working as a programmer using C++ only for quite some time
now, I never felt the need to do any development under Java, but that
has now change; as we all know Java is not longer a programming
language that can be ignored. Thus I have decided to port or convert my
C++ library to Java, but I have run in to a little bit of a problem
with the concept of package:
Say for instance, if I have a class foo.java in a subdirectory named
[.../dev/java/packages/package_one ] the file would look like this:
--------
package pakage_one;
public class MyClass{
    private String name;
    private int age;
    public MyClass(){
        name = "John";
        age = 11;
    }
    public String getName(){return this.name;}
    public int getAge(){return this.age;}
}
but if I have a later write a class that creates an object of the above
class the compiler cannot find it!!

Can anyone tell me what I am doing wrong?
Or can you point me to a place where I can find examples and a clear
explanation of how to do this?
TIA

import packages.*;
public class Runner{
    public static void main(String args[]){
        System.out.println("Run me");
        MyClass obj;
    }
}
Remi Arntzen - 16 Aug 2005 05:44 GMT
you are importing "packages.*"
thus MyClass should be of package "packages.pakage_one"
so that the import would be like "import packages.pakage_one.*"
However, depending on your main-directory it could also be "import
pakage_one.*"

Now it might work.
Shorty - 17 Aug 2005 09:16 GMT
Actually, as I understand it, "packages" is just a directory containing
the packages. It is not part of the package arborescence. If "MyClass"
is in the package "pakage_one" as it is declared, then the import
should be "import pakage_one.*;" or "import pakage_one.MyClass;".

However, in order for this to work, the directory "packages" must be in
the classpath (check the classpath environment variable and the
-classpath command line option to the java command).

Hope this helps.
jalkadir - 18 Aug 2005 14:19 GMT
Thank you all, for your prompt response.

Before I go any further, I would like to give more information about
what I am doing.
Files and Dir_Tree:
~~~~~~~~~~~~~~~
*Top_Directory
...\java
*Subdirectory or Library
...\java\jaa

*Files
'..\java\AlBuraqRunner.java'
'..\java\AlBuraqRunner.class'
'..\java\Jamiil.java'
'..\java\jaa\Jamiil.class'

This the code:
~~~~~~~~~~~
package jaa;
public class Jamiil{
    private String name;
    private int age;
    public Jamiil(){
        name = "Jamiil";
        age = 11;
    }
    public String getName(){return this.name;}
    public int getAge(){return this.age;}
}
import jaa.*;
public class AlBuraqRunner
{
    public static void main(String args[])
    {
        System.out.println("Sabron Jameel");
        Jamiil obj = new Jamiil();
        //System.out.println("My name is: " + obj.getName());
    }
}

Now, the problem is that after I type:
javac -g AlBuraqRunner.java
I get an error message that reads:
AlBuraqRunner.java:7: cannot access Jamiil
bad class file: c:\jamiil\dev\java\java\Jamiil.class
class file contains wrong class: jaa.jamiil
Please remove or make sure it appears in the correct subdirectory of
the classpath.
-----
I don't understand the message, what am I doing wrong?

Thanks in advance
Shorty - 19 Aug 2005 13:03 GMT
Isn't there some confusion in your directory names ?

between

'..\java\jaa\Jamiil.class'

and

' bad class file: c:\jamiil\dev\java\java\Jamiil.class '

is Jamiil.class in java\jaa or java\java ?
jalkadir - 20 Aug 2005 12:01 GMT
Oops, sorry. <:)
the line should be
' bad class file: c:\jamiil\dev\java\jaa\Jamiil.class'

Thanks
Andrew Thompson - 20 Aug 2005 12:12 GMT
> Oops, sorry. <:)
> the line should be
> ' bad class file: c:\jamiil\dev\java\jaa\Jamiil.class'

You seemed to take a great deal of effort earlier to
be accurate, so here is a tip that might help both you
and anybody trying to help.

Output can be copied directly from the Windows CLI
be dragging the mouse pointer across the text and
pressing the 'enter'[1] key.

Done.

[1] <http://www.physci.org/kbd.jsp?key=enter>

HTH

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"If I could find the reason, I'd know the answer why"
Status Quo 'Gerdundula'



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.