Error
Type mismatch: cannot convert from int to String
or change the data type of element.
Type mismatch: cannot convert from int to String
Error Type
Compile Time
Compile Time
Sample Code
public class Test {
String element = "Hello";
private void method(){
element = '0';
}
}
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';
}
}