简体   繁体   English

如果我编译任何java程序,我收到此错误

[英]If i compile any java program, i got this error

If i compile any java program, I got this error 如果我编译任何java程序,我收到此错误

b1.java:3: cannot access String
bad class file: .\String.java
file does not contain class String
Please remove or make sure it appears in the correct subdirectory of the classpath.
public static void main(String ar[])throws IOException{

As visible from your compilation step in the terminal, 从终端的编译步骤可以看出,

String is already a Java-library class available in JDK.

Hence,you can't give such name to your program/class. 因此,您不能将此名称赋予您的程序/类。

Hence,you receive such error. 因此,您收到此类错误。

Try naming it something else like public class MyString and rename your source code as MyString.java ---recompile it and then you won't receive such errors. 尝试将其命名为public class MyString ,并将源代码重命名为MyString.java ---重新编译它,然后您将不会收到此类错误。

String is a datatype defined within the Java-Library. String是Java-Library中定义的数据类型。 You cannot name a variable as String or any other name of datatypes, in that way you cannot name it for a class. 您不能将变量命名为String或任何其他数据类型名称,这样您就无法为类命名。

String is in-built Class in Java. String是Java中的内置类。 Hence you can not give the name for Class as String. 因此,您不能将Class的名称赋予String。 you can check it by - just give the name for Class as Class string and save it as string.java . 你可以检查它 - 只需给Class作为Class string的名称,并将其保存为string.java now it will compile and run properly. 现在它将编译并正常运行。 but according to naming convention first letter of Class Name must be in UpperCase , so you can name it as MyString.java 但根据命名约定,类名的第一个字母必须在UpperCase中,因此您可以将其命名为MyString.java

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

相关问题 当我为xml编译以下程序以进行转换时,我遇到了以下错误 - I got following error when I compile following program for xml to excel to conversion 如何编译和运行Java程序? - How can I compile and run a Java program? Java程序中的编译错误 - Compile Error in java program 我可以编译Java程序,但不能运行Java程序 - I am able to compile the java program but not able to run a java program 编译程序时出现错误(线程“ main”中的异常java.lang.ArrayIndexOutOfBoundsException) - I get the Error when i compile my program (Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException) 编译时,为什么在Java程序中出现“找不到符号”错误? - Why am I getting a “cannot find symbol” error in my java program when I compile? 我在Java上的SQL上遇到语法错误,没有任何错误 - I got syntax error for SQL on java, where there isn't any error 我将如何在Scala程序中编译和执行Java程序? - how would i compile and execute a java program in a scala program? 我已经设法编译java程序但我无法执行它 - I have managed to compile java-program but I cannot execute it 使用Eclipse IDE可以完美地编译和运行Java程序,但是当我使用“ javac”时,会导致错误 - Using Eclipse IDE can compile and run the Java program perfectly but when I use 'javac' it is resulting to Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM