• Post Reply Bookmark Topic Watch Topic
  • New Topic

bad class file error  RSS feed

 
Sana siddiqui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting following error while compiling any of my java programs.

cannot acces String
bad source file: .\String.java
file does not contain class String
Please remove or make sure it appears in the correct subdirectory of the source path

i've reinstalled java 2-3 times, it isn't working.
Please help..
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please show us what the source code looks like and what your compilation command looks like?
 
Sana siddiqui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source code:

class check
{
public static void main(String args[])
{
int a= Integer.parseInt(args[0]);
int b= Integer.parseInt(args[1]);
int c=a+b;
System.out.println("Sum="+c);
}
}


compilation command:

E:\java programs>javac check.java
check.java:3: error: cannot access String
public static void main(String args[])
^
bad source file: .\String.java
file does not contain class String
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a file of your own named String.java? Remove or rename it and report back.
 
Sana siddiqui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much... it worked
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moral of the story: don't name your classes the same as existing JDK classes. And especially not the same as classes in the java.lang package.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!