Results 1 to 4 of 4

Thread: something goes wrong when I try to run java .class files

  1. #1
    Join Date
    Sep 2009
    Beans
    3

    something goes wrong when I try to run java .class files

    Why hello there!
    I seem to be having some trouble running .class files from bash. At first I thought I was just a complete retard and forgot to how to but it seems that the problem is a bit more complicated. However I am able to compile java programs.

    For example. Lets save I have a program like this

    Code:
    public class yourmom
    {
    
    
         public static void main(String[] args)
         {
                 while(true)
                 {
                         System.out.println("your mom loves my phallus");
                 }
         }
    
    }
    I am able to compile the .class file but not run it. I know the problem is probably an environment variable or a program thats not installed. I am fairly sure that I have the runtime installed because I can run programs like openoffice. Any help would be appreciated.

    I should also mention the error I receive when i try to run the program. I get the generic class cannot be found error shown here.

    Exception in thread "main" java.lang.NoClassDefFoundError: yourmom
    Caused by: java.lang.ClassNotFoundException: yourmom
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 68)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:336)
    Could not find the main class: yourmom. Program will exit.

  2. #2
    Join Date
    Aug 2006
    Location
    Alfandra
    Beans
    355
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: something goes wrong when I try to run java .class files

    What is the exact command line you use to run the program? It sounds to me like it's not looking in the right directory.

  3. #3
    Join Date
    Sep 2009
    Beans
    3

    Re: something goes wrong when I try to run java .class files

    java nameofprogram. I also tried java ./nameofprogram which did not work

  4. #4
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    5,442
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: something goes wrong when I try to run java .class files

    And how did you compile it? Please can you post the commands you used both to compile it and to run it. Don't try to filter the output - include the commands and all their output and the prompts. Your hiding information from us only hinders finding the problem.

Tags for this Thread

Bookmarks

Posting Permissions

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