Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Java Programming 24-Hour Trainer by Yakov Fain
|
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
 
Old July 20th, 2011, 11:45 PM
Registered User
 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old July 21st, 2011, 05:19 AM
Registered User
 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old August 2nd, 2011, 12:18 AM
Registered User
 
Join Date: Aug 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy 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.
 
Old April 1st, 2012, 09:22 PM
Registered User
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old April 2nd, 2012, 06:54 AM
Authorized User
 
Join Date: Feb 2012
Posts: 30
Thanks: 5
Thanked 4 Times in 4 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to make htaccess work. markdawkins BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 April 17th, 2011 02:31 PM
unable to get Chapter 4 To do list 2 to work abhi BOOK: Professional Android 2 Application Development 2 June 2nd, 2010 09:38 PM
Has anyone located all of the source code yet? gary167 BOOK: Access 2003 VBA Programmer's Reference 0 November 10th, 2006 08:21 PM
How to Handle VARIANT return type ronaldo07 Visual C++ 0 June 15th, 2006 04:41 PM
Scheduled DTS package does not work niravp SQL Server DTS 5 May 26th, 2004 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.