Results 1 to 20 of 30
Thread: strange error in eclipse
- 06-18-2011, 07:09 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
strange error in eclipse
Hey everyone.
I'm trying to write a simple program but I keep getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: Main
Caused by: java.lang.ClassNotFoundException: Main
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)
and here is the code:
class apples{
public static void main(String args[]){
int test=6;
if (test==9){
System.out.println("yes");
}
else{
System.out.println("No");
}
}
}
Thanks in advance!
- 06-18-2011, 07:22 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
Well, your "class" is "apples", not Main, so edit the run configuration to call the proper class.
- 06-18-2011, 08:51 AM #3
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
I'm not sure I understand. I just need to change apples to main? why's that? I thought you could make up a name for the class?
- 06-18-2011, 09:10 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
You can call the class anything you like. (Within reason, and it is best to start with a capital letter).
The point masijade was making is that you have to tell Eclipse to run the class you mean it to. And not a class called Main which is what you are doing at the moment.
- 06-18-2011, 04:20 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
Alright I changed the class to Apples and everything works fine and dandy. Why is it that it can't be called main though?
- 06-18-2011, 04:35 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
You can call a class (almost) everything you want but you have to tell Eclipse exactly that name if you want to run it; you called your class 'apples' but you told Eclipse that it had to run a class named 'Main'; that, of course, doesn't make sense and the JVM told you so: it couldn't find a class named 'Main'. Eclipse can do a lot for you but it can't corrrect your mental mistakes you made.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 06-21-2011, 06:38 AM #7
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
Hello everyone,
Here's another weird error I'm getting. Does this make sense to anyone?
Thanks in advance!
Exception in thread "main" java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Nativ e Method)
at java.io.File.createNewFile(File.java:883)
at ContactFileDAO.loadContacts(ContactFileDAO.java:19 )
at Menu.<init>(Menu.java:13)
at ContactBook.main(ContactBook.java:10)
- 06-21-2011, 06:41 AM #8
"No such file or directory"
How is that weird? It makes perfect sense to me.
- 06-21-2011, 06:43 AM #9
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
but I don't have a thread named "main"?
- 06-21-2011, 06:48 AM #10
Yes you do. All programs have at least one thread.
"ContactFileDAO.java:19"
This is where your problem is. On that line you are doing something with a file that does not exist or at least not where your Java program is looking for it.
Java Code:System.out.println(FFFF.getAbsolutePath());
- 06-21-2011, 06:50 AM #11
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
This is line 19. Doesn't really tell me anything :S
file.createNewFile();
- 06-21-2011, 07:58 AM #12
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
Here is the program. Anyone find a problem?
Thanks!
Jasons Address Book.zip
- 06-21-2011, 08:22 AM #13
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
And what is "file" defined as? What is the path that that File object refers to and does that path exist, and do you have permission to write there? If you look at the stacktrace pointed above you will see the call to that method. Come on, you have got to be able to analyse problems better than this.
- 06-21-2011, 08:28 AM #14
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
I'm sorry I'm new to Java. I had a friend send me an example file so that I could study it but I couldn't get it to run. I saw this:
Java Code:File file = new File(dir + FILE_NAME); file.createNewFile();
- 06-21-2011, 08:30 AM #15
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
And what are "dir" and "FILE_NAME" defined as? And does concating them like this lead to a proper a path? Or is the file separator missing between them? As already suggested use println to print the value of the path.
Edit: P.S. this is what comes of blindly copying code with no understanding of what it does. Example code should be used as nothing more than a nudge in the (hopefully) right direction, it should not be cut-n-pasted.
- 06-21-2011, 06:32 PM #16
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
There's also this next snippet of code right after it:
Java Code:Scanner fileReader = new Scanner(file); Contacts contacts = new Contacts();
EDIT* Also, my friend just told me he wrote the code on windows and since I'm on a Mac there might have to be a few changes. What should be different?Last edited by stevenpalomino; 06-21-2011 at 06:34 PM.
- 06-21-2011, 06:36 PM #17
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
I'm sorry, buht I'm out of here.
- 06-21-2011, 06:38 PM #18
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
ok Thanks anyway.
- 06-21-2011, 06:44 PM #19
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
dir+FILE_NAME should result in a sensible (potential) file name. Why not print it just before you attempt to create a file:
Java Code:System.out.println(dir+FILE_NAME);
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 06-21-2011, 06:49 PM #20
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
Similar Threads
-
BufferedReader throwing strange error
By DragonGhola in forum Advanced JavaReplies: 4Last Post: 06-16-2011, 11:17 AM -
Strange Compilation Error About Generics
By dhafirnz in forum Advanced JavaReplies: 7Last Post: 11-16-2010, 09:54 AM -
Strange Error
By AJArmstron@aol.com in forum New To JavaReplies: 1Last Post: 04-18-2010, 10:31 PM -
Strange eclipse behaviour with new version
By KingOfLions in forum EclipseReplies: 0Last Post: 09-10-2009, 02:42 PM -
strange Error message
By little_polarbear in forum New To JavaReplies: 4Last Post: 08-26-2008, 12:45 AM
Bookmarks