Results 1 to 6 of 6
- 06-23-2010, 11:35 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
- 06-24-2010, 12:16 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.
- 06-24-2010, 01:29 AM #3
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
- 06-24-2010, 02:42 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
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.
- 06-24-2010, 02:49 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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:
This line is telling the compiler about the identity of the class you are calling File.Java Code:import java.io.File;
- 06-24-2010, 04:29 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM -
Hello World
By MadeinFinland in forum IntroductionsReplies: 0Last Post: 02-19-2009, 06:34 AM -
hello world
By wayne.seymour in forum IntroductionsReplies: 2Last Post: 02-11-2009, 01:19 PM -
Hello World!
By Silentstormz in forum IntroductionsReplies: 3Last Post: 09-09-2008, 04:33 AM -
Hello World
By JacobKrustchinsky in forum IntroductionsReplies: 5Last Post: 05-04-2008, 05:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks