This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Author's Code  RSS feed

 
Randy Draper
Greenhorn
Posts: 2
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I trying to learn Java from "Java A Beginners Guide" Fifth Edition by Herber Schildt. In the fourth chapter he has this program that I copied and compiled but I get errors from his example. Because I am new I do not know how to fix the problems. Here is the program.


I am using the latest Eclipse and on line 3 Eclipse is saying "The type Vehicle is already defined".

On line 31 Eclipse is stating "Exception in thread "main" java.lang.NoSuchFieldError: fuelcap
at AddMeth.main(AddMeth.java:31)"

These are things I don't understand how to fix and I would like someone to help repair the code so it actually works. Thanks

Randy
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have these in one file?

Also, please use the codetags (I would format it for you, but I can't)

WP
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have another Vehicle.java file lying around somewhere? Or perhaps it's just a Vehicle.class file that needs to be updated. Try deleting all you .class files and recompiling.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That is a pretty dreadful design you have been given, and I have seen similar in other books. The fields should have private access in the Vehicle class, and should be initialised via the constructor. If you want to display them in other classes, they can be made accessible via public getXXX methods.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You ought not to try to run anything which Eclipse tells you there is an error in.

At this stage, you are probably better off not using an IDE at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!