• 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

Author's Code

 
Greenhorn
Posts: 2
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Master Rancher
Posts: 4830
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic