• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problems with initialization

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone

I really am new to Java and have hit my first hurdle.

I have declared 3 instance variables:
and created 2 objects t222 and z333. (no problems here)

I am now wanting to set the studentCode of the course object referenced by t222 to "T222" and the same for the studentCode, from z333 to "Z333".

I know what I have is not right because I keep getting the error:
incompatible types; found: student.Course, required: java.lang.String at line 29, column 12 I have



Could anyone point out to me PLEASE what I am doing wrong becuase I am going round in circles.

Any help would be much appreciated.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The variable T222 is declared as type String. You're trying to assign an instance of Course to it.

A Course is not a String.

(PS: Have you seen the JavaRanch Naming Policy? You can edit your name here. Thanks!)
[ February 11, 2006: Message edited by: marc weber ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since T222, etc. are declared to be of type String, you cannot assign the reference to point to an object other than a String. (For other classes, you could point a reference to an object of that class or any of its subclasses, but String is a final class and you can't create a subclass of it.)
 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for answering. I have now changed the name.

Although I understand what you are saying, is it possible you could post an example so I can see where I have gone wrong.

Thanks
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to guess what you were trying to do, so forgive me if I go astray.



So, the following would work:

 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Craig, I see it now....feeling pretty foolish but glad that I found this message board.

Thanks again.
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic