• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
Rancher
Posts: 4327
59
  • 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: 76867
366
  • 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: 76867
366
  • 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.
 
No holds barred. And no bars holed. Except this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic