java.lang.ClassNotFoundException - Issue
Hi Guys!
I´m currently learning how to handle multiple classes, but I´m having a rough time with an error.
Here is my current code for the both classes:
Tuna.java
Code:
package client1;
public class Tuna {
public void simplemessage(){
System.out.println("Enkelt meddelande");
}
}
Class99.java
Code:
package client1;
public class Class99 {
public static void main(String[] args) {
Tuna test = new Tuna();
test.simplemessage();
}
Error Code:
java.lang.NoClassDefFoundError: client1/Class99
Caused by: java.lang.ClassNotFoundException: client1.Class99
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 05)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 46)
Any suggestions on what is wrong with the code I wrote? Or is it something wrong with my Jdeveloper settings?
Re: java.lang.ClassNotFoundException - Issue
The exception is saying that the runtime cannot find the client.Class99 class.
Make sure that the class exists - that is make sure you have compiled both classes. At the moment Class99 has a syntax error and will not compile.
Re: java.lang.ClassNotFoundException - Issue
Thanks for the reply!
I have bypassed the current error by making a new project with new classes.
Here is the new code:
is.java
Code:
package client;
public class is {
public static void simplemessage(String name){
System.out.println("Hej");}
}
isotop.java
Code:
package client;
public class isotop {
public static void main(String[] args) {
is olle = new is();
olle.simplemessage();
}
}
I´m using this guys tutorials: Java Programming Tutorial - 14 - Using Multiple Classes - YouTube
What am I doing wrong? He clearly says in the video to first create an object from the class that will be used in the method.
I do that by writing "is olle = new is();".
Then he suggests that I should do "olle.nameofmymethod" which in this case is "olle.simplemessage". But I get this annoying error: simplemessage(java.lang.String) in client.is cannot be applied to ().
Thanks for your help! If I can´t understand this part then I won´t be able to continue his videos :-(
Re: java.lang.ClassNotFoundException - Issue
Sorry, I don't use JDeveloper. But I think you did the right thing by starting again. It is very annoying when IDEs like JDeveloper try and run a program that has not been compiled - no good can come from that.
Quote:
simplemessage(java.lang.String) in client.is cannot be applied to ()
Basically the compiler is telling you that you have a method simplemessage() that takes a string argument but you are trying to use it without giving it that argument.
Try:
Code:
package client;
public class isotop {
public static void main(String[] args) {
is olle = new is();
olle.simplemessage("world");
}
}
Of course you are not doing anything with the string "world", but that's OK. You could do something with it if you wanted to:
Code:
package client;
public class is {
public static void simplemessage(String name){
System.out.println("Hej, " + name);
}
}
-----
Sorry to be a pest, but there's a couple of things you could be fussy about now - because it'll pay off later. First be very consistent with how you indent code. } should in a line on its own and should line up with the corresponding {. Secondly classes should start with a capital letter, eg Is. The class and the file have to agree so the class client.Is will correspond with the file client\Is.java