ERROR - Type mismatch: cannot convert from char to String

Error

Type mismatch: cannot convert from int to String


Error Type

Compile Time


Sample Code 

public class Test {
String element = "Hello";

private void method(){

element = '0';
}
}

Cause

String cannot be assigned a character literal.

Resolution

Either we should assign element the string literal.



public class Test {
private String element = "Hello";

private void method(){
element = "0";
}
}

or change the data type of element.



public class Test {
private String element = 'H';

private void method(){
element = '0';
}
}