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 / December 2007

Tip: Looking for answers? Try searching our database.

Help with packages getting started

Thread view: 
BlitzA - 28 Dec 2007 13:57 GMT
I still need some help getting the Elements package working with java.

I've typed this in command prompt:

set CLASSPATH=C:\Program Files\Java\jdk1.6.0_03\bin\element.zip
So now it let's me compile this code:

import element.*;

public class DrawRect
{
   public static void main(String args[])
   {
       DrawingWindow d = new DrawingWindow();
       Rect cornerRect = new Rect(10,10,20,30);

       d.draw(cornerRect);
   }
}

So I get a file called DrawRect.class

When I type in java DrawRect to run the code it says:

C:\Program Files\Java\jdk1.6.0_03\bin>java DrawRect

Exception in thread "main" java.lang.NoClassDefFoundError: DrawRect

Someone please help I've been trying to get this working for hours and
haven't even started my project lol
Lew - 28 Dec 2007 14:23 GMT
> I still need some help getting the Elements package working with java.
>
[quoted text clipped - 26 lines]
> Someone please help I've been trying to get this working for hours and
> haven't even started my project lol

You should not be creating files in the Java bin/ subdirectory - that's not a
data directory.  Really, you shouldn't have write privilege to that directory,
but that's a problem with Windows.

Create some separate projects directory and do your work there.

Use the -classpath (or -cp) option to your compilation and execution of Java
code.  The tutorials on java.sun.com go into this.

Signature

Lew

BlitzA - 28 Dec 2007 14:46 GMT
>> I still need some help getting the Elements package working with java.
>>
[quoted text clipped - 10 lines]
>Use the -classpath (or -cp) option to your compilation and execution of Java
>code.  The tutorials on java.sun.com go into this.

Ok, your going to have to explain things.

I understand that I should have the files in a different directory than the
Java bin subdirectory, although does that really have any effect on my
program not working?

Also I still don't understand this classpath.

I just need to know how to get elements working.

It seems like I'd set it right so that it can compile as it did, it just
doesn't run the .class file that was created, this is what I don't understand.

Can you explain more please :)

(sorry im a begginner)
BlitzA - 28 Dec 2007 14:47 GMT
>>> I still need some help getting the Elements package working with java.
>>>
[quoted text clipped - 18 lines]
>
>(sorry im a begginner)

Possibly a step-by-step guide of how to get this working If you have time ? -
I have a feeling it''s quite simple to do.
Lew - 28 Dec 2007 14:53 GMT
Lew wrote:
>>> code.  The tutorials on java.sun.com go into this.

>> Ok, your going to have to explain things.
...
> Possibly a step-by-step guide of how to get this working If you have time ? -
> I have a feeling it''s quite simple to do.

That's what the tutorials are for.  Why should we have to explain things, when
Sun did such a good job already?  Read the tutorials.

Once you've read the tutorials you might consider Usenet as a way to deepen
your understanding.  I wouldn't expect anyone here to rewrite the tutorials
for your convenience, though.

Signature

Lew

BlitzA - 28 Dec 2007 16:03 GMT
>Lew wrote:
>>>> code.  The tutorials on java.sun.com go into this.
[quoted text clipped - 10 lines]
>your understanding.  I wouldn't expect anyone here to rewrite the tutorials
>for your convenience, though.

So theres a tutorial that specifically shows you how to make elements work
with JDK 6.0 in a small step-by-step guide?

If so please can you give the link?

Cheers.
Knute Johnson - 28 Dec 2007 18:46 GMT
>> Lew wrote:
>>>>> code.  The tutorials on java.sun.com go into this.
[quoted text clipped - 15 lines]
>
> Cheers.

I don't know where the tutorial is either but you can look here for some
more information on CLASSPATH;

www.knutejohnson.com/classpath.html

CLASSPATH is one of the trickiest pieces of programming with Java.

There are some important tips to remember;

1) You don't want to set the CLASSPATH environment variable except in
   a few rare circumstances
2) The CLASSPATH has to include all the bits you want to compile or run
3) If you use the -jar option on the command line to run a program
   the -classpath or -cp command line options are ignored.

2 is probably where your problem lies.  I don't see a . in the CLASSPATH
so how is the runtime going to find your class?

Signature

Knute Johnson
email s/nospam/knute/

Lew - 28 Dec 2007 23:53 GMT
Lew wrote:
>>>>>> code.  The tutorials on java.sun.com go into this.
>>>>> Ok, your going to have to explain things.

BlitzA wrote:
>>>> Possibly a step-by-step guide of how to get this working If you have
>>>> time ? -

I assumed you were asking about my advice:
> Use the -classpath (or -cp) option to your compilation and execution of Java code.
> The tutorials on java.sun.com go into this.

But from your question
>> So theres a tutorial that specifically shows you how to make elements
>> work with JDK 6.0 in a small step-by-step guide?

I see that I was mistaken.  My advice was to fix the classpath - how to do
that step by step is covered by Sun's tutorials.

>> If so please can you give the link?

http://java.sun.com look around for the links to the tutorials.

As I said, I'm talking about tutorials with respect to setting the classpath
for Java, which is where your problem lies.

In a nutshell, you have to tell Java where the class is that you're trying to
run, and as I pointed out earlier, that should most definitely not be in the
Java installation directory tree, most especially particularly not in its bin/
subdirectory.

> I don't know where the tutorial is either but you can look here for some
> more information on CLASSPATH;
[quoted text clipped - 7 lines]
> 1) You don't want to set the CLASSPATH environment variable except in
>    a few rare circumstances

Important point, to be sure.

> 2) The CLASSPATH has to include all the bits you want to compile or run

Lower-case classpath does, too.  More precisely, it has to include all the
parent directories and JARs of the bits you want.

> 3) If you use the -jar option on the command line to run a program
>    the -classpath or -cp command line options are ignored.

Also the CLASSPATH envar is ignored then.

> 2 is probably where your problem lies.  I don't see a . in the CLASSPATH
> so how is the runtime going to find your class?

Lower-case.  If there is no CLASSPATH envar and you don't specify a -classpath
option, Java assumes "." as the classpath.

Sun's tools docs contain the page
<http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html>
that gives excruciating detail.

So for the OP, this means picking a project directory, say, C:/projects, and
building your stuff in a subdirectory there.

For project "example" with the source in a tree rooted at subdirectory src/,
and classes going into a tree rooted at build/classes/:

cd /projects/example/src
javac -d ../build/classes com/lewscanon/example/App.java
cd ../build/classes
java com.lewscanon.example.App

If you don't cd to the build/classes subdir, you can use -classpath to run the
program:

cd /anywhere/you/like
java -classpath /projects/example/build/classes com.lewscanon.example.App

If I needed a JAR to pull in a library, like /projects/libs/foo.jar, then it'd
look like this:

java -classpath /projects/example/build/classes:/projects/libs/foo.jar \
     com.lewscanon.example.App

The colon (:) would be a semicolon (;) in Windows environments.

Once all that is straight that original error should melt away.

Signature

Lew

Lew - 28 Dec 2007 23:56 GMT
> I still need some help getting the Elements package working with java.
...
> import element.*;
...
> So theres a tutorial that specifically shows you how to make elements work
> with JDK 6.0 in a small step-by-step guide?

What are these "elements"?
Where do they come from?
Why don't they have a real package name?

Signature

Lew
This post contains three requests for information.



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.