Example.java:6:21
java: incompatible types: java.lang.String cannot be converted to int
In Java you may get incompatible types compilation errors when you try to save incompatible type value in a specific data type which does not support it.
The error message "incompatible types: java.lang.String cannot be converted to int" occurs in when you try to assign a value of type String to a variable of type int, which is not possible because they are different data types.
Examples:public class Example {
public static void main(String[] args) {
int myInt = "Harry"; //Required type: int Provided: String
}
}
int myInt = "25"; //Required type: int Provided: String

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!