Results 1 to 3 of 3
  1. #1
    Rambar is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default Basic question about compiling

    Hello! Im starting to learn Java on my spare time (I just realised I dont like Pascal anymore), and I've come across a curious problem.
    I've made a simple (very simple!) program under Geany on Linux. Here is the souce
    Java Code:
    import java.util.*;
    class Suma{
     public static void main(String args[]){
      Scanner a = new Scanner(System.in);
      System.out.println("Dame un número");
      int b = a.nextInt();
      System.out.println("Dame otro número");
      int c = a.nextInt();
      System.out.println("La suma de " + b + " y " + c + " es " + (c+b));
     }
    }
    I can compile it and run it succesfuly on Geany. But when I try the manual approach, compiling and running from a terminal, I get this:
    Java Code:
    santiago@Samorost:~/Java$ java Suma.class
    Exception in thread "main" java.lang.NoClassDefFoundError: Suma/class
    Caused by: java.lang.ClassNotFoundException: Suma.class
    	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:323)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
    Could not find the main class: Suma.class. Program will exit.
    santiago@Samorost:~/Java$
    That comes after succesfuly compiling the program via javac. To be honest, I dont really know much about linux either. So I'd like if you could explain what went wrong here. Thanks for your help.

    PD: By the way, I just joined the forums. I'd also like to say hi to the community. ;)

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Hi!!!!!!!!!!!
    Welcome to Java forum!!!!!!!

    when u run take out .class.Go thru sun site for understanding fundas.
    java Suma
    Ramya:cool:

  3. #3
    Rambar is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    Oh damn! I'm feeling stupid right now!

    Thanks for the help, I am impressed by the quickness of the reply. But I should have checked Sun site first, I apologize.

Similar Threads

  1. Netbeans newbie question on compiling
    By DaFlake in forum NetBeans
    Replies: 4
    Last Post: 07-30-2009, 07:04 PM
  2. Basic question on OOP.
    By madthinker in forum New To Java
    Replies: 7
    Last Post: 01-26-2009, 07:09 PM
  3. Basic question about EJB
    By javaplus in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-15-2008, 05:44 PM
  4. Very basic question
    By gvi in forum New To Java
    Replies: 2
    Last Post: 10-30-2007, 06:30 PM
  5. basic question about files
    By oregon in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 02:34 AM

Posting Permissions

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