• Post Reply Bookmark Topic Watch Topic
  • New Topic

running first java program  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am newbie this my first post. I've started learning programming in JAVA from Headfirst Java.
I have installed jdk1.7.0_03, and set the system path. C:\Program Files (x86)\Java\jdk1.7.0_03
I can compile my program's using
but when i try to run that is
A expection is thrown. please help

here is the first example from the book




I don't know what to do. I have tried diffrent codes but still same problem

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The error message tells you what is wrong:

Exception in thread "main" java.lang.NoClassDefFoundError: Beersong (wrong name: chap01/BeerSong)

The class is named BeerSong, not Beersong and it is in a package named chap01.

Make sure you spell the class name correctly, and make sure that your directory structure matches the package structure. The book should tell you exactly how that works (read it carefully and follow the instructions exactly). If you want to know more about packages, have a look at this tutorial: Lesson: Packages.
 
Davinderpro java
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I deleted from the code and it run perfectly.

can you tell me the purpose of package chap01. in the java code.

how to use code with package. what's the importance of packages

I am referring this article.

http://docs.oracle.com/javase/tutorial/java/package/index.html
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Davinderpro java wrote:
can you tell me the purpose of package chap01. in the java code.

how to use code with package. what's the importance of packages

I am referring this article.

http://docs.oracle.com/javase/tutorial/java/package/index.html


That section of the tutorial answers those questions. Work through it, and then if you have any more specific questions or didn't understand some part of it, post again.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!