Results 1 to 13 of 13
Thread: Java Packages
- 06-10-2011, 09:15 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 10
- Rep Power
- 0
Java Packages
Hi! Everybody,
I'm new to java. Please help me solve this problem:
I have one package named: pack in d:\
In "pack" I have two other package: " A" and "B".(d:\pack\A and d:\pack\B)
Package "A" consist of a file known as "Greet.java"
Package "B" consist of a file known as "TestGreet.java"
Greet.java:
package pack.A;
public class Greet{
public void disp()
{
System.out.println("In Greet Class!");
}
}
TestGreet.java:
package pack.B;
import pack.A.*;
public class TestGreet{
public static void main(String args[])
{
Greet G= new Greet();
G.disp();
}
}
I tried setting classpath to d:\
so files got compiled but not executed...
Please, let me know what can be done to execute it...
Regards,
Shital jain.
- 06-10-2011, 09:19 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What happens when you execute them? Errors? If so, post the exact error message(copy/paste not paraphrasing)
- 06-10-2011, 09:28 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,540
- Rep Power
- 11
And tell us the command you use to run the program and location from where you run it (if you are using the command line), or what IDE you are using (if you are not).
- 06-10-2011, 09:30 AM #4
Member
- Join Date
- Jun 2011
- Posts
- 10
- Rep Power
- 0
Hi!
The execution went this way....
C:\>set classpath=d:\
C:\>d:
D:\>cd pack
D:\pack>javac a\Greet.java
D:\pack>javac b\TestGreet.java
D:\pack>java b\TestGreet
Exception in thread "main" java.lang.NoClassDefFoundError: b\TestGreet
D:\pack>
ShitalJain
- 06-10-2011, 09:31 AM #5
Member
- Join Date
- Jun 2011
- Posts
- 10
- Rep Power
- 0
simply using notepad editor and jdk1.6
- 06-10-2011, 09:32 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Cd all the way into the package and just type "java TestGreet"
- 06-10-2011, 09:36 AM #7
Member
- Join Date
- Jun 2011
- Posts
- 10
- Rep Power
- 0
nothing is working...
I tried:
D:\pack>cd\
D:\>java TestGreet
Exception in thread "main" java.lang.NoClassDefFoundError: TestGreet
D:\>cd pack
D:\pack>java TestGreet
Exception in thread "main" java.lang.NoClassDefFoundError: TestGreet
D:\pack>cd B
D:\pack\B>java TestGreet
Exception in thread "main" java.lang.NoClassDefFoundError: TestGreet
D:\pack\B>
Please let me knoe what exactly has to be tried...
- 06-10-2011, 09:38 AM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Where is the .class file located?
- 06-10-2011, 09:40 AM #9
Member
- Join Date
- Jun 2011
- Posts
- 10
- Rep Power
- 0
its there in B for TestGreet and A for Greet
- 06-10-2011, 09:54 AM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,540
- Rep Power
- 11
Try
(The first command is just to check that TestGreet.class really does exist.) The classpath is specified here using the "-cp ." arguments. This is more flexible than setting an OS variable.Java Code:D:\>dir pack\B D:\>java -cp . pack.B.TestGreet
The java executable expects the name of the class which has the main() method. This is the full name of the class, ie including the package of which it is a part.
- 06-10-2011, 09:57 AM #11
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Someone else will hopefully help you soon. I must be too tired, I am unable to even replicate the errors(damn compilation error I am running into...hence the too tired part).
- 06-11-2011, 07:40 AM #12
Member
- Join Date
- Jun 2011
- Posts
- 10
- Rep Power
- 0
- 06-11-2011, 08:14 AM #13
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,540
- Rep Power
- 11
Similar Threads
-
Java packages and confusion (Yes, I've RTFM)
By unaligned in forum New To JavaReplies: 12Last Post: 06-03-2011, 05:45 PM -
How to find java packages
By h.ghorashi in forum New To JavaReplies: 1Last Post: 02-16-2011, 06:03 PM -
Java packages / statsic problem - Please help!
By brendan_1986 in forum New To JavaReplies: 14Last Post: 02-09-2011, 01:51 PM -
Java Packages/Jars
By Silentstormz in forum Advanced JavaReplies: 4Last Post: 09-14-2008, 07:58 PM -
Importing packages from the packages within same application.
By sta2003 in forum New To JavaReplies: 3Last Post: 02-12-2008, 11:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks