*
The moose likes Beginning Java and the fly likes problem incompatible types... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem incompatible types..." Watch "problem incompatible types..." New topic
Author

problem incompatible types...

Brian Walsh
Greenhorn

Joined: Feb 06, 2002
Posts: 17
I was having problems with incompatible types on a string to be read. I want to read a string and each letter be printed on a seperate line...right now I am working on this line....

here is the error when compiling.

A:\Chapter 3\Bench\StringRead.java:22: incompatible types
found : char
required: java.lang.String
place = Character.toLowerCase(sentence.charAt(i));
^
1 error
Tool completed with exit code 1


I understand the basics of objects, but I am still working on how to use the api right. Could anyone point me out to a tutorial that would help me? Thank you very much. Here is the entirety of the program still in progress....

import cs1.Keyboard;
public class StringRead
{

public static void main (String[] args)
{
String num, place, sentence;
int i , letter;
System.out.println ("Please put in a string of letters or a sentence...");
sentence = Keyboard.readString();
for (i = 0; i < sentence.length();++ i)
{
place = Character.toLowerCase(sentence.charAt(i));
}
}
}


Thanks again for your help and time....
-Calv1n


-Thanks in Advance
Tim B.
Greenhorn

Joined: Feb 03, 2003
Posts: 10
Hi Brian,
The error occurs because you're trying to assign a 'char' to a 'String' object. Your 'place' variable is declared as a String object, but the static 'toLowerCase()' method of the 'Character' class, returns a 'char'.
A solution to this problem might be the following lines of code:

Or if you like to do everything on one line:

Hope this helped you out a bit.
Greetings,
Tim
[ February 03, 2003: Message edited by: Tim B. ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem incompatible types...
 
Similar Threads
Help with english to morse code program, I have no idea what I'm doing
Reverse the words in a string
problem with incompatible types comile error
Another Loop question...
String index out of range