Home > Archive > Java Help > August 2005 > My own java library, like in C++
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
My own java library, like in C++
|
|
| jalkadir 2005-08-16, 4:01 am |
| 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 2005-08-16, 4:01 am |
| 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 2005-08-17, 4:07 am |
| 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 2005-08-18, 6:00 pm |
| 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 2005-08-19, 4:20 pm |
| 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 2005-08-20, 7:57 am |
| Oops, sorry. <:)
the line should be
' bad class file: c:\jamiil\dev\java\jaa\Jamiil.class'
Thanks
| |
| Andrew Thompson 2005-08-20, 7:57 am |
| On 20 Aug 2005 04:01:02 -0700, jalkadir wrote:
> 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
--
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'
|
|
|
|
|