• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having trouble running code.  RSS feed

 
Matthew Taheri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I'm suddenly having trouble running classes from the command line. Previously, things were working. I cant imagine I'm doing anything differently. The sample code is below and any help is welcome.

Code:

class HelloWorldTester{
public static void main(String[] args){
System.out.println("Hello World");
}
}


Terminal output:


C:\Users\mattman\Dropbox\Programming\Java>javac helloWorldTest.java

C:\Users\mattman\Dropbox\Programming\Java>java HelloWorldTester.class
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldTester/clas
s
Caused by: java.lang.ClassNotFoundException: HelloWorldTester.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: HelloWorldTester.class. Program will exit.

C:\Users\mattman\Dropbox\Programming\Java>
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the name of the java file exactly the same as the name class?

HelloWorldTester.java
 
Matthew Taheri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Affirmative. What are you thinking it may be?
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Taheri wrote:Affirmative. What are you thinking it may be?

It looks like the file name begins with a lowercase h: javac helloWorldTest.java
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually from the output you have written you are suppose to drop the .class extension from the file in order to run it otherwise you'll keep getting the error that's displayed...

Should be: C:\Users\mattman\Dropbox\Programming\Java>java HelloWorldTester (drop the .class)
 
Matthew Taheri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:Actually from the output you have written you are suppose to drop the .class extension from the file in order to run it otherwise you'll keep getting the error that's displayed...

Should be: C:\Users\mattman\Dropbox\Programming\Java>java HelloWorldTester (drop the .class)


I love you in ways that only a beginner-level programmer can understand.

P.S. This is why you don't stare at code for 6 hours straight without a break.
 
Campbell Ritchie
Marshal
Posts: 56585
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is actually a confusing feature.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!