 |
BOOK: Java Programming 24-Hour Trainer by Yakov Fain
 | This is the forum to discuss the Wrox book Java Programming 24-Hour Trainer
by Yakov Fain; ISBN: 978-0-470-88964-0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Java Programming 24-Hour Trainer by Yakov Fain section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 20th, 2011, 11:45 PM
|
|
Registered User
|
|
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Lesson 5 variant - unable to work if code is located in a package
Hello,
Perhaps I don't completely understand what is required here, but I have tried to place all my classes inside a package named com.mycompany.lesson5
I understand that this particular lesson/example was supposed to have all its classes placed in 'default'. When placed in 'default', the program runs and behaves as expected.
Out of curiousity, I tried rewriting the whole thing and placing the classes into the package mentioned above. It compiles and Runs just fine from within the IDE, giving the error message "Sample usage of the program... etc" since understandably, args[] is empty.
However, running from the command line (and this time, having to browse deeper in than bin... actually bin/com/mycompany/lesson5) gives some error message. I have since deleted the project, but I will redo it shortly just so I can update this post with the error message presented.
This is obviously related to the classes being in a package... is anyone able to explain this?
|
|

July 21st, 2011, 05:19 AM
|
|
Registered User
|
|
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
A little update:
It seems that this isnât specific to lesson 5.
I wrote Hello World again, this time placing it within a package.
It runs fine from the IDE, but when I use the console/command prompt and navigate into the specific folder with the .class file⦠typing in âjava HelloWorldâ will give the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong nam
e: com/mycompany /lesson1/HelloWorld)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: HelloWorld. Program will exit.
Again, if I didnât place the class within a package and simply left it at default, the program will run from the console/command prompt. Why is this so?
|
|

August 2nd, 2011, 12:18 AM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Lesson 5 - Try It
Hi,
I'm new to Java, and I've been following the video tutorials and reading the book to get a grasp on the language. However, while trying to do the Lesson 5 try it, I keep running into an error that's preventing me from running the program in the command prompt. I can run it using the Java Application, and I get the print line "Sample usage..." but in the command prompt it keeps saying that it could not find the main class (I would attach a picture of the error if I knew how). I double checked the TestTax.class pathway and see nothing wrong. I'm I missing something or simply doing something wrong? Please help, I'd greatly appreciate it. Thank you.
|
|

April 1st, 2012, 09:22 PM
|
|
Registered User
|
|
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ditto
I'm having the noclassdeffounderror also.
Google searches haven't helped at all. Lots of suggestions, but nothing that seems to work.
Java programs work fine from within Eclipse, but if I try to run them from cmd, error.
|
|

April 2nd, 2012, 06:54 AM
|
|
Authorized User
|
|
Join Date: Feb 2012
Posts: 30
Thanks: 5
Thanked 4 Times in 4 Posts
|
|
Hello, everybody.
I downloaded the solution for lesson 5, Lesson5Solution.zip, from here:
http://code.google.com/p/practicaljava/downloads/list
It uses
Code:
package com.practicaljava.lesson5.tryit;
I successfully ran the program from the command line using:
java -classpath C:\Eclipse\Cristina\workspace\Lesson5\bin com.practicaljava.lesson5.tryit.TestTax
TestTax.class and Tax.class are located in C:\Eclipse\Cristina\workspace\Lesson5\bin\com\prac ticaljava\lesson5\tryit.
If I issue the command from C:\Eclipse\Cristina\workspace\Lesson5\bin, I need not include the -classpath option anymore, as follows:
C:\Eclipse\Cristina\workspace\Lesson5\bin> java com.practicaljava.lesson5.tryit.TestTax
Hope this helps.
|
|
 |
|