java.lang.NoClassDefFoundError
Imma new java user :confused::confused:
i don't know what's the problem on my code
Code java:
public class Main {
public void queueExample() {
Queue queue = new LinkedList();
queue.add("item1");
queue.add("item2");
queue.offer("item3");
queue.offer("item4");
System.out.println("remove: " + queue.remove());
System.out.println("element: " + queue.element());
System.out.println("poll: " + queue.poll());
System.out.println("peek: " + queue.peek());
}
public static void main (String [] args) {
new Main() queueExample();
}
}
and the output of this code is
java.lang.NoClassDefFoundError: Main
Exception in thread "main"
Process completed.
:confused::confused::confused:
Re: java.lang.NoClassDefFoundError
I'm pretty sure you're just missing a period between Main() and queueExample(). Although I don't see how that would result in the Exception you're talking about.
Re: java.lang.NoClassDefFoundError
Re: java.lang.NoClassDefFoundError
-Edit...Removed Post.
anonymous001 corrected convention issue and started new Thread..which made my post void :P
Re: java.lang.NoClassDefFoundError
Quote:
Originally Posted by
newbie
-Edit...Removed Post.
anonymous001 corrected convention issue and started new Thread..which made my post void :P
Code Java:
import java.util.LinkedList;
import java.util.Queue;
/**
*
* @author javadb.com
*/
public class Main {
/**
* Example method for using a Queue
*/
public void queueExample() {
Queue queue = new LinkedList();
//Using the add method to add items.
//Should anything go wrong an exception will be thrown.
queue.add("item1");
queue.add("item2");
//Using the offer method to add items.
//Should anything go wrong it will just return false
queue.offer("Item3");
queue.offer("Item4");
//Removing the first item from the queue.
//If the queue is empty a java.util.NoSuchElementException will be thrown.
System.out.println("remove: " + queue.remove());
//Checking what item is first in line without removing it
//If the queue is empty a java.util.NoSuchElementException will be thrown.
System.out.println("element: " + queue.element());
//Removing the first item from the queue.
//If the queue is empty the method just returns false.
System.out.println("poll: " + queue.poll());
//Checking what item is first in line without removing it
//If the queue is empty a null value will be returned.
System.out.println("peek: " + queue.peek());
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main().queueExample();
}
}
i tried this code but it didn't run. :D
Re: java.lang.NoClassDefFoundError
For the sake of everyone's sanity, I urge you to keep each problem in its own Thread. Please keep the issue with running your code in the Thread you started for it: http://www.javaprogrammingforums.com...ore-error.html
Full disclosure- I'm not a mod. Do what you want, but keep in mind that you should probably be making it easier for people to help you, not harder.
Re: java.lang.NoClassDefFoundError
Quote:
Originally Posted by
KevinWorkman
For the sake of everyone's sanity, I urge you to keep each problem in its own Thread. Please keep the issue with running your code in the Thread you started for it:
http://www.javaprogrammingforums.com...ore-error.html
Full disclosure- I'm not a mod. Do what you want, but keep in mind that you should probably be making it easier for people to help you, not harder.
Sorry kev :( i accidentally clicked the submit :[
okay. sorry sorry :(
Re: java.lang.NoClassDefFoundError
Quote:
i tried this code but it didn't run
This is quite uninformative as to the problem...does it compile? Are there exceptions?
Re: java.lang.NoClassDefFoundError
Ran unchanged for me. Please post how you are attempting to run your code, and any errors.