This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Names - Windows XP Problem?

 
Andrew Babaian
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused. I can compile and run:
public class test
{
public static void main(String[] args)
{
System.out.println("hello world!");
}
}
but I can compile, but can't run:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("hello world!");
}
}
I get this exception:
Exception in thread "main" java.lang.NoSuchMethodError: main
I also can compile but can't run:
public class helloworld
{
public static void main(String[] args)
{
System.out.println("hello world!");
}
}
I get this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong name: HelloWorld)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
What gives?
Thanks
Andrew
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that your "HelloWorld" class is in a file named "HelloWorld.java", and your "helloworld" class is in a file named "helloworld.java". Case matters.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...Except to Windows file names. The OS sometimes gets a little bit fnicky about actually recognizing a change to a file name if the only thing that you change is the case. You may need to copy the file to another directory with the new case, delete the old file, and then move the copied file to the directory where you want it.
Basic summary: Java cares about case, but Windows doesn't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic