Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2009
    Posts
    18
    Rep Power
    0

    Default Porblem to run a simples program

    Hello I have this, simple program:
    Java Code:
    public class FileReader {
    
      public void openFile () {
      
      }
    
      public void readFile () {
        System.out.println ("Boto");
      }
    }
    Java Code:
    import java.io.*;
    
    public class Main {
      public void main (String [] args) {
        FileReader fileReader = new FileReader ();
        fileReader.readFile();
      }
    }
    Putting it into a folder and calling the program from there, I receive:
    ./java Procurador\ de\ Texto/Main
    Exception in thread "main" java.lang.NoClassDefFoundError: Procurador de Texto/Main (wrong name: Main)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :791)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:482)
    So, what I am doing wrong?

    Thanks for the input

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Porblem to run a simples program

    You have called your class Main. Make sure it is in a file called Main.java and that you compile it correctly. Also there is a class in the io package called FileReader. Since your class is also called FileReader this can lead to confusion.

  3. #3
    Join Date
    Dec 2009
    Posts
    18
    Rep Power
    0

    Default Re: Porblem to run a simples program

    Quote Originally Posted by Junky View Post
    You have called your class Main. Make sure it is in a file called Main.java and that you compile it correctly. Also there is a class in the io package called FileReader. Since your class is also called FileReader this can lead to confusion.
    Yes, the file it is Main.java and it compiles correctly. I also took knowledge about the FileReader stuff and changed the class name.
    What else can be?

    P.S: There is flash adds that are really bothering me. They cover the reply of the thread, forcing me to copy and paste the text somewhere else to read it better. Don't see a button to kill them

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Porblem to run a simples program

    Copy and paste the exact commands you use to compile and run your program.

  5. #5
    Join Date
    Dec 2009
    Posts
    18
    Rep Power
    0

    Default Re: Porblem to run a simples program

    Quote Originally Posted by Junky View Post
    Copy and paste the exact commands you use to compile and run your program.
    ./javac Procurador\ de\ Texto/Main.java Procurador\ de\ Texto/FileManager.java

    ./java Procurador\ de\ Texto/Main
    FileManager replacing FileReader

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Porblem to run a simples program

    You need to either have a -classpath added to your command, or be in the directory containing the class.
    Java thinks you are trying to execute a class called "Procurador\ de\ Texto/Main", whcih you aren't.
    You're trying to execute Main.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Join Date
    Dec 2009
    Posts
    18
    Rep Power
    0

    Default Re: Porblem to run a simples program

    Quote Originally Posted by Tolls View Post
    You need to either have a -classpath added to your command, or be in the directory containing the class.
    Java thinks you are trying to execute a class called "Procurador\ de\ Texto/Main", whcih you aren't.
    You're trying to execute Main.
    thanks.

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  2. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  3. porblem with components
    By 0xHexaDecimal in forum AWT / Swing
    Replies: 12
    Last Post: 06-21-2010, 06:33 PM
  4. Porblem Executing Queries in Java
    By ajit.mishra@gs.com in forum New To Java
    Replies: 1
    Last Post: 09-05-2008, 07:31 AM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •