Results 1 to 9 of 9
  1. #1
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default can't run the java file

    hi, I was wondering what might be wrong with my java setup on my system

    i can compile my java files with no errors and the class files corresponding the java file will appear.

    problem comes when I try to do the java command

    I am able to compile this with no errors using 'javac H.java' on the command line

    Java Code:
    public class H {
    	public static void main (String[] args) {
    		System.out.println('fubar");	
    	}
    }
    but when I do 'java H' on the terminal it gives me this error message

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: H
    Caused by: java.lang.ClassNotFoundException: H
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    Could not find the main class: H. Program will exit.
    should I need to declare stuff like system variables or anything that is necessary to setup first

    thanks for reading, all suggestions would be appreciated :D

  2. #2
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    correction

    Java Code:
    System.out.println('fubar");

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by kulangotski View Post
    correction

    Java Code:
    System.out.println('fubar");
    That should be:

    Java Code:
    System.out.println("fubar");
    Didn't your compiler complain when you compiled your code?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    jeez,,

    the correction was the same with the wrong code on the first post. Sorry, already fixed that.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by kulangotski View Post
    jeez,,

    the correction was the same with the wrong code on the first post. Sorry, already fixed that.
    So does your class run now?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    still got the same problem with the class though, not seeing the compiled class

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by kulangotski View Post
    still got the same problem with the class though, not seeing the compiled class
    For the record: when you do:

    Java Code:
    javac H.java
    Don't see see a file 'H.class' in the directory where (also) H.java is stored? Does your compiler complain about anything?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    oh, when I run this using 'javac H.java'

    Java Code:
    //H.java
    
    public class H {
    	public static void main (String[] args) {
    		System.out.println("fubar");	 //got the quotes right
    	}
    }
    I get no complain, but when I do 'java H', i get this

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: H
    Caused by: java.lang.ClassNotFoundException: H
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    Could not find the main class: H. Program will exit.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by kulangotski View Post
    oh, when I run this using 'javac H.java'

    Java Code:
    //H.java
    
    public class H {
    	public static void main (String[] args) {
    		System.out.println("fubar");	 //got the quotes right
    	}
    }
    I get no complain, but when I do 'java H', i get this

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: H
    Caused by: java.lang.ClassNotFoundException: H
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    Could not find the main class: H. Program will exit.
    When you do an 'ls' (or 'dir' depending on your OS) in the directory where your H.java file is stored, can you see an H.class file? Is that directory writable to you?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. how to split large xml file into small xml file in java
    By enggvijaysingh@gmail.com in forum XML
    Replies: 2
    Last Post: 02-07-2011, 09:34 AM
  2. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM
  3. Replies: 7
    Last Post: 05-23-2008, 03:46 AM
  4. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  5. Converting text file(.txt) to JPG file(.jpg) in java
    By javadeveloper in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 04:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •