• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Incompatible Object Type?

 
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am reading Head First Design Patterns.  It is my only 2nd book into the world of Java. You could say that I am a beginner programmer.

I have a question. I copied and typed as I went with the code in the book.

There is one error that I'm getting.  The error is this.

Error:(8, 46) java: incompatible types: Chapter2Weather.WeatherData cannot be converted to Chapter2Weather.Subject



I followed the code exactly as written in the book. there were two classes that weren't in the book but was in the code catalog online for this specific book.

here's the specific line that gets this error.



other codes that might help you out why I'm getting this error




Let me know. Thanks!
 
Mike Skyriach
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I found the error.

For future reference,



I replaced "Subject" with "WeatherData" two times in that code block and it worked. Like this:


This is for pg. 57-60 in Head First Design Patterns 10th anniversary.  In case someone is going through the same thing I did.

Thanks
 
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for following up with that, Mike! Although... it's possible that the authors intended WeatherData to implement Subject and omitted to do that. Could you try the code as is from the book and just make that change instead?

(I gave you a cow for the work you did there.)
 
Mike Skyriach
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Thanks for following up with that, Mike! Although... it's possible that the authors intended WeatherData to implement Subject and omitted to do that. Could you try the code as is from the book and just make that change instead?

(I gave you a cow for the work you did there.)



Hmm. I followed exactly as written in the book and downloaded statisticsDisplay & forecastDisplay off wickedlysmartt (where the book source codes are located in).  I was comparing these two classes against the WeatherData class and found out that they were using different objects for the argument rather than the Subject.

However, the WeatherData class was already implementing the Subject interface when the error appeared.  What possible fixes would I have to do in order to make that work with the Subject being passed to the constructor?

Thank you for the cow!  I was not expecting that!
 
Paul Clapham
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm. If Chapter2Weather.WeatherData is actually implementing Chapter2Weather.Subject then you should not get the error message which you posted in your original post. So there's something fishy going on. Unfortunately I can't tell what that is based on the code you've posted so far.
 
machines help you to do more, but experience less. Experience this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic