简体   繁体   English

如何修复“字符串无法解析为类型”

[英]how to fix 'String cannot be resolved to a type'

when i compile the code in eclipse, throwing error当我在eclipse中编译代码时,抛出错误

"Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    String cannot be resolved to a type
    String cannot be resolved to a type
    System cannot be resolved
    String cannot be resolved to a type
    System cannot be resolved   "

but i have written "String" from capital "S"但我用大写的“S”写了“String”

Below is the code :下面是代码:

 public class student {
        int id;
        String name;
    }

class TestStudent1 {
    public static void main(String[] args) {
        student s = new student();
        s.name = "ram";
        s.id = 101;
        System.out.println(s.name);
        System.out.println(s.id);
    }
}

Make sure you have saved your files and make TestStudent1 class public and change the file name as TestStudent1.java as below,确保您已保存文件并将 TestStudent1 类设为公开,并将文件名更改为 TestStudent1.java,如下所示,

class student {
    int id;
    String name;
}

public class TestStudent1 {
public static void main(String[] args) {
    student s = new student();
    s.name = "ram";
    s.id = 101;
    System.out.println(s.name);
    System.out.println(s.id);
}
}

here is the output:这是输出:

ram 101公羊 101

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM