不兼容的类型:java.lang.String无法转换为String [英] incompatible types: java.lang.String cannot be converted to String

查看:1063
本文介绍了不兼容的类型:java.lang.String无法转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,基本上我正在学习一些Java(基本ATM),但遇到了一些错误,但是很快就解决了。因此,我遇到了一个我从未听说过的新怪异错误,我进行了研究,但没有找到可以帮助我的答案。

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

这是我的代码:

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


推荐答案

这是由于在与尝试访问<$的类相同的程序包中创建一个名为 String 的类引起的c $ c> java.lang.String 如Steffan和Stultuske的评论所指出。

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.

这篇关于不兼容的类型:java.lang.String无法转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆