Meaningless Drivel is fun!
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem incompatible types..." Watch "problem incompatible types..." New topic

problem incompatible types...

Brian Walsh

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\ 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....

-Thanks in Advance
Tim B.

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.
[ February 03, 2003: Message edited by: Tim B. ]
I agree. Here's the link:
subject: problem incompatible types...
It's not a secret anymore!