3

So basically I'm learning some java (The basics ATM) and I had a few errors but solved them pretty fast. So I got this new weird error that I've never heard about and I researched and found no answers that could help me.

I removed the old project and get the old errors on new projects

So this is my code:

import javax.swing.*;

public class Hej {
  public static void main (String[] arg) {
    JOptionPane.showMessageDialog(null, "Hej!");
  }
}

And this is my error on the file that I removed about a month ago:

C:\Users\Droxx\Documents\javamapp>javac Hej.java
.\String.java:10: error: incompatible types: java.lang.String cannot be converte
d to String
        r = "Silver ";
            ^
.\String.java:11: error: incompatible types: java.lang.String cannot be converte
d to String
        l = "2";
            ^
.\String.java:13: error: cannot find symbol
        i = r.substring(0,1);
             ^
  symbol:   method substring(int,int)
  location: variable r of type String
.\String.java:17: error: cannot find symbol
                JOptionPane.showMessageDialog(null, "Level:" + a);
                                                               ^
  symbol:   variable a
  location: class String
4 errors
0

1 Answer 1

5

This is caused by creating a class called String in the same package as the class trying to access java.lang.String as pointed out in the comments by Steffan and Stultuske.

Sign up to request clarification or add additional context in comments.

1 Comment

And make sure if you have an old String.class hanging around, you remove it too!! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.