Results 1 to 6 of 6
  1. #1
    Genesis is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default Hello world, what am I doing wrong?!

    SOLVED :)


    Thanks for all the help, I was simply missing a semi colon to end my initial statement.

    Go figure.
    Last edited by Genesis; 06-24-2010 at 02:45 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Could you post the error message?

    The message (and the line number of your code that it refers to) is usually helpful in identifying what went wrong.

    [Edit] Also could you clarify *when* you get the error. Your original post says that it occurs when you try and run the program. But, as posted, the code won't compile.
    Last edited by pbrockway2; 06-24-2010 at 12:19 AM.

  3. #3
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    i copied and pasted your code into my IDE. i changed a few things around and it worked in mine.

    PHP Code:
    import java.io.File;
    
    public class Main {
    
        public static void main(String[] args) {
    
        File listroot = new File("c:/");
        File[] files = listroot.listFiles();
    
        System.out.println("Print root files from c:");
    
            for (File file : files) {
                if (file.isDirectory())
                continue;
                System.out.println(file.getPath());
            }
        }
    }
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  4. #4
    Genesis is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    Here is the output I get when I try to run my code:




    --------------------Configuration: ListFiles - JDK version 1.6.0_20 <Default> - <Default>--------------------
    java.lang.NoClassDefFoundError: ListFiles
    Caused by: java.lang.ClassNotFoundException: ListFiles
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    Could not find the main class: ListFiles. Program will exit.
    Exception in thread "main"
    Process completed.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    That error occurs because the code has not been compiled. (Hence the NoClassDefFoundError.)

    In fact alacn's post corrected the line that was causing the code not to compile: put "import" at the very start before "java.io.File". Ie it should look like:

    Java Code:
    import java.io.File;
    This line is telling the compiler about the identity of the class you are calling File.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Genesis View Post
    SOLVED :)


    Thanks for all the help, I was simply missing a semi colon to end my initial statement.

    Go figure.
    Please don't edit the past posts once you've found the solution. People who are looking into your thread may be confused because of that. Post a new replay, to explain what you've done to solve the problem.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. Hello World
    By MadeinFinland in forum Introductions
    Replies: 0
    Last Post: 02-19-2009, 06:34 AM
  3. hello world
    By wayne.seymour in forum Introductions
    Replies: 2
    Last Post: 02-11-2009, 01:19 PM
  4. Hello World!
    By Silentstormz in forum Introductions
    Replies: 3
    Last Post: 09-09-2008, 04:33 AM
  5. Hello World
    By JacobKrustchinsky in forum Introductions
    Replies: 5
    Last Post: 05-04-2008, 05:41 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
  •