Jump to content

Type mismatch: cannot convert from java.lang.String to DataTypesCasting.String


newcoder1010
 Share

Recommended Posts

Hello,

I am practicing java from this link. 

https://www.w3schools.com/java/java_strings.asp

JAVA

        String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        System.out.println("The length of the txt string is: " + txt.length());
Quote

Type mismatch: cannot convert from java.lang.String to DataTypesCasting.String

Fixed it using the suggested fix:

        java.lang.String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

Can you please tell me why I had to replace String by   java.lang.String? 

Thanks!

Link to comment
Share on other sites

It sounds like you are importing some packages with another class named "String".

You have to specify java.lang.String because you have imported a different String class and it assumes you meant that other one.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...