Jump to content
Sign in to follow this  
newcoder1010

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

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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...