• 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

problem with incompatible types comile error

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a program that will read a string of letter and then be able to spit out the number of each vowel of that string.Here is the code I have been writing. I am unable to figure out why for the variable place I am unable to make it a variable string, rather than a integer that will compile fine.

I get the compile error

C:\Documents and Settings\Administrator\Desktop\Schoolie\Spring 2002\CS161\Workbench\SayLetter.java:30: incompatible types
found : char
required: java.lang.String
place = Character.toLowerCase(Letters.charAt(spot));//says where to look in string
^
1 error
Tool completed with exit code 1


I wanted to thank you in advance for helpong me because tihs eludes me as to I am very much a beginner. THANK YOU FOR YOUR TIME
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am unable to figure out why for the variable place I am unable to make it a variable string, rather than a integer that will compile fine.


Basically, you have a type mismatch since the right-hand side returns a char while the left-hand side is expecting a String object.
I took the liberty of tweaking your code a bit.
If you can use primitives, better use them since creating unnecessary objects is wasteful. So used chars instead, and since I have chars now I took advantage of a switch.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a clarification of the excellent post above ;-), the charAt() method is returning a char and this is where your problem was occuring
 
Brian Walsh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help you guys I figured out the problem and I decided to use the switch statement instead, I will definatly use that in the future. THANK AGAIN!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic