Reputation: 17
If i compile any java program, I got this error
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{
Upvotes: 0
Views: 72
Reputation: 41
String is in-built Class in Java. Hence you can not give the name for Class as String. you can check it by - just give the name for Class as Class string
and save it as 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
Upvotes: 0
Reputation: 88
String is a datatype defined within the 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.
Upvotes: 0
Reputation: 19158
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.
Upvotes: 3