• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Head First Design Patterns - Can't run

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all:

I'm *so* new to Java that I'm almost ashamed to post me question ;-)

I have a PC with WinXP - SP2 and Java runtime and Java SDK 1.5 installed. I also have Borland's JBuilder 2005 Foundry Version installed.

I wish the run the sample code from the Head First Design Patterns book, but can't get it to run. I hve also downloaded the execution bath file, still no luck.

Boy, I'm slow today!!

The error I'm getting is:
Exception in thread "main" java.lang.NoClassDefFoundError: headfirst/strategy/MiniDuckSimulator

and the command line is:
java -cp ./classes headfirst.strategy.MiniDuckSimulator

Please help!!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The -CP tells the java command where to start looking for classes. The package path on the classname has to match the directory structure from that point. Check and see if your directories look like this:

If that's all correct, we'll try to figure out what to check next.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you be ashamed when you're new? Now, had you been coding Java for five years, maybe that feeling would be justified (though I still feel it never is ... I'm just making a point). And please, no one wants to read anyone disparaging themselves. We're all friends here!Isn't Windows just wonderful?! The problem is that you're using a Unix path separator. Try this:or simply remove the ".\" altogether.
 
Martin Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
The -CP tells the java command where to start looking for classes. The package path on the classname has to match the directory structure from that point. Check and see if your directories look like this:

If that's all correct, we'll try to figure out what to check next.



Stan:

Maybe I need some more basic Java help, let me explain.

I've been a C,C++, Pascal and C# programmer for more than 20 years, so my OS skills and general programming skills should be okay (I think!), but Java is new and that's where I'm having trouble.

I'm not too sure what I should be executing. Is it a .java file on the hard disk or a .java file inside a .jar file. The structure inside the hfdp.jar is root|src|headfirst|??? where ??? are actual direcories containg the java code. I have extracted the contents of the jar file to harddisk starting at d:\hfdp and then src, headfirst etc.

I have replaced the ./ with .\ for my Windows installation.

Finally the file MiniDuckSimulator.class does not exist, just the MiniDuckSimulator.java file, this seems to me to be a critial issue, but I don't know how to generate the .class file.

Regards,
Martin.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah, you need to compile the thing first.
Like C and C++ Java is a compiled language. The downloadable stuff for the book contains only the source files.

go to the classes directory and type to compile the application class and everything it needs (that's not compiled already). The compiler will figure out the dependencies for you.
You can compile from elsewhere using the appropriate compiler options, running javac without any parameters will give you a list (or use the documentation for the JDK).
 
Martin Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

go to the classes directory



What do you mean by 'classes directory'?

and type to compile the application class and everything it needs (that's not compiled already). The compiler will figure out the dependencies for you.



I have tried this but it doesn't seem to see the 'included' java files.

The source file has 'package headfirst.strategy;' on the first line, what is this doing?

TIA,
Martin.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO...

1. Its not a good idea to start java with "Head First Design Patterns". Maybe you should get "Head First Java" first or "Just Java", get some experience with the concepts of Java programming and then leap on the design pattern bandwagon. You can buy the book at the following links:
--> Head First Java
--> Just Java 2

2. Or.. you could start your journey in Java Programming by the Sun recommended tutorial . Find the link to the basic tutorial here.
First Cup of Java
 
Martin Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Agni Vartula:
IMHO...

1. Its not a good idea to start java with "Head First Design Patterns". Maybe you should get "Head First Java" first or "Just Java", get some experience with the concepts of Java programming and then leap on the design pattern bandwagon. You can buy the book at the following links:
--> Head First Java
--> Just Java 2



Agni:

I bought the Design Patterns book not knowing it's examples were in Java (I'm a C++ and C# programmer with more than 20 years software development experience) and have found the book a 100% winner.

I'm just interested in running the examples, but... now it seems like I'm getting hooked on Java :-) I've already ordered the Head First Java book (hasn't arrived yet), but the question still stands: How do I run the sample code?

Regards,
Martin.
 
Subhash Bhushan C
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Martin,
Apart from writing a source file in Java, its important that you set some PATH and CLASSPATH variables appropriately, for your program to compile and run.

The link that I provided earlier, to "First Cup of Java" has these instructions. Please take the time and trouble to go through it, because even if I am able to explain everything, I will not be able to do it better than them.

Here are the defined links:

Windows Installation instructions

Your first java program... How to code, compile and run
 
Martin Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agni:

Thanks for your time. I have printed the pages you indicated and will study them later today.

I'm sure this will anwser my questions,

Regards,
Martin.
 
Martin Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, all done and dusted :-))

I followed the links Agni suggested and also got myself the eclipse.org IDE and its all up and running.

Thanks to all who contributed.

Regards,
Martin.
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic