|
-
June 2nd, 2009, 05:54 PM
#1
NoClassDefFoundError ???????
So I'm trying to run this code but it keeps giving me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: PhrasebotMac
I think this is what happened. So, yesterday I dragged my folder with all my source code for Phrasebot onto my dock. I look to see if it's still in the directory. Indeed it is. Then when I open up Eclipse it tells me it can't find the class I was working on but it somehow can find all the others in that folder. Great. So I go to delete the file because I had tried everything. So I go back to Eclipse and try to create the class again. It tells me that there is already a class named Phrasebot. But the class and source file don't exist anymore so I have no clue why it's telling me this. So I make a new class called PhrasebotMac and copy the source code into it and change everything that's called Phrasebot to PhrasebotMac. Today I go to launch it and it gives me this error. Please help!!!!!!!!
Code:
//Phrasebot is property of shakenearth.com
//Code by Thomas Lisankie
//You may not use any of this code
//you may not distribute this program either
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import javax.swing.Box;
import java.io.*;
import java.net.*;
public class PhrasebotMac implements ActionListener {
JTextArea midgui;
JButton phrasemaker;
Box boxleft;
JTextField nounbox1;
JTextField nounbox2;
JTextField nounbox3;
JTextField adjbox1;
JTextField adjbox2;
JTextField adjbox3;
JTextField verbbox1;
JTextField verbbox2;
JTextField verbbox3;
String[] nounarray;
String[] adjarray;
String[] verbarray;
int countnoun;
int countadj;
int countverb;
int ran1;
int ran2;
int ran3;
String funny;
ArrayList<String> nouns;
ArrayList<String> adjectives;
ArrayList<String> verbs;
public static void main(String[] args){
try{
PhrasebotMac gui = new PhrasebotMac();
gui.go();
}catch(Error Ex){
Ex.printStackTrace();
}
}
public void go() {
JPanel pcenter = new JPanel();
JFrame frame = new JFrame("Phrasebot");//makes a new JFrame called "Phrasebot"
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//sets the default close operation to EXIT_ON_CLOSE
boxleft = new Box(BoxLayout.Y_AXIS);
JPanel bigpanel = new JPanel();//makes a new JPanel called bigpanel
bigpanel.setLayout(new BoxLayout(bigpanel,BoxLayout.Y_AXIS));//sets bigpanel's default layout to BoxLayout
JPanel spacer = new JPanel();//makes a new JPanel called spacer
spacer.setLayout(new BoxLayout(spacer, BoxLayout.Y_AXIS));//sets spacer's layout to BoxLayout
JLabel label = new JLabel(" ");//makes a new JLabel
spacer.add(label);//adds label to spacer
bigpanel.add(spacer);//adds spacer to bigpanel
JPanel peast = new JPanel();//makes a new panel called peast
bigpanel.add(peast);//bigpanel adds peast
peast.setLayout(new BoxLayout(peast,BoxLayout.Y_AXIS));//sets peast's layout to boxlayout
JButton morenoun = new JButton("More Nouns");//makes a new button called more noun with the text "More Nouns"
morenoun.addActionListener(new morenounListener());//morenoun adds an actionlistener which is a morenounlistener()
peast.add(morenoun);//peast adds morenoun
JButton clearnoun = new JButton("Clear Nouns");//makes a new button called clearnoun with the text "Clear Nouns"
clearnoun.addActionListener(new clearnounListener());//clearnoun adds an actionlistener which is a clearnounlistener()
peast.add(clearnoun);//peast adds clearnoun
JLabel spacer2 = new JLabel(" ");//makes a new label called spacer2
peast.add(spacer2);//peast adds spacer2
JButton moreadj = new JButton("More Adjectives");//makes a new button called moreadj with the text "More Adjectives"
moreadj.addActionListener(new moreadjListener());//moreadj adds an actionlistener which is a moreadjlistener()
peast.add(moreadj);//peast adds moreadj
JButton clearadj = new JButton("Clear Adjectives");//makes a new button called clearadj with the text "Cear Adjectives"
clearadj.addActionListener(new clearadjListener());//clearadj adds an actionlistener which is a clearadjlistener()
peast.add(clearadj);//peast adds clearadj
JLabel spacer3 = new JLabel(" ");//makes a new label called spacer3
peast.add(spacer3);//peast adds
JButton moreverb = new JButton("More Verbs");//makes a new button called moreverb with the text "More Verbs"
moreverb.addActionListener(new moreverbListener());//moreverb adds an actionlistener which is a moreverblistener()
peast.add(moreverb);//peast adds moreverb
JButton clearverb = new JButton("Clear Verbs");//makes a new button called clearverb with the text "Clear Verbs"
clearverb.addActionListener(new clearverbListener());//clearverb adds an actionlistener which is a clearverbListener()
peast.add(clearverb);//peast adds clearverb
JLabel savespacer = new JLabel(" ");//makes a new label called savespacer
peast.add(savespacer);//peast adds savespacer
JButton savewords = new JButton("Save Words");//makes a new button called save words
savewords.addActionListener(new savewordsListener());//savewords adds an actionlistener which is a savewordsListener()
peast.add(savewords);//peast adds savewords
JButton savesession = new JButton("Save Phrases");//creates a new button called savesession with the text "Save Phrases"
savesession.addActionListener(new savesessionListener());//savesession adds an actionlistener which is a savesessionListener()
peast.add(savesession);//peast adds savesession
JLabel quickspacer = new JLabel(" ");//makes a new label called quickspacer
peast.add(quickspacer);//peast adds quickspacer
JButton quick1 = new JButton("Quickie Button 1");//makes a new button called quick1 with the text "Quickie Button 1"
quick1.addActionListener(new quick1Listener());//
peast.add(quick1);
JButton quick2 = new JButton("Quickie Button 2");
quick2.addActionListener(new quick2Listener());
peast.add(quick2);
JButton quick3 = new JButton("Quickie Button 3");
quick3.addActionListener(new quick3Listener());//100
peast.add(quick3);
JPanel pwest = new JPanel();
pwest.setLayout(new BoxLayout(pwest,BoxLayout.Y_AXIS));
JPanel bigpanel2 = new JPanel();
bigpanel2.add(pwest);
Font midfont = new Font("Comic Sans MS", Font.BOLD, 18);
midgui = new JTextArea(10,20);
midgui.setEditable(false);
midgui.setLineWrap(true);
midgui.setFont(midfont);
JScrollPane scroll = new JScrollPane(midgui);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pcenter.add(scroll);
nounbox1 = new JTextField("Noun ");
nounbox2 = new JTextField("Noun ");
nounbox3 = new JTextField("Noun ");
JLabel spacer4 = new JLabel(" ");
pwest.add(nounbox1);
nounbox1.addActionListener(this);
pwest.add(nounbox2);
nounbox2.addActionListener(new nounbox2Listener());
pwest.add(nounbox3);
nounbox3.addActionListener(new nounbox3listener());
pwest.add(spacer4);
adjbox1 = new JTextField("Adjective ");
adjbox2 = new JTextField("Adjective ");
adjbox3 = new JTextField("Adjective ");
JLabel spacer5 = new JLabel(" ");
pwest.add(adjbox1);
adjbox1.addActionListener(new adjbox1Listener());
pwest.add(adjbox2);
adjbox2.addActionListener(new adjbox2Listener());
pwest.add(adjbox3);
adjbox3.addActionListener(new adjbox3Listener());
pwest.add(spacer5);
verbbox1 = new JTextField("Verb ");
verbbox2 = new JTextField("Verb ");
verbbox3 = new JTextField("Verb ");
pwest.add(verbbox1);
verbbox1.addActionListener(new verbbox1Listener());
pwest.add(verbbox2);
verbbox2.addActionListener(new verbbox2Listener());
pwest.add(verbbox3);
verbbox3.addActionListener(new verbbox3Listener());
JPanel psouth = new JPanel();
JPanel bigpanel3 = new JPanel();
bigpanel3.add(psouth);
phrasemaker = new JButton("Make A Phrase!");
phrasemaker.addActionListener(new phrasemakerListener());
psouth.add(phrasemaker);
boxleft.add(nounbox1);
boxleft.add(nounbox2);
boxleft.add(nounbox3);
Box.createVerticalGlue();
boxleft.add(adjbox1);
boxleft.add(adjbox2);
boxleft.add(adjbox3);
Box.createVerticalGlue();
boxleft.add(verbbox1);
boxleft.add(verbbox2);
boxleft.add(verbbox3);
frame.setSize(800,600);//sets the size of the JFrame
frame.setVisible(true);//sets the ability to see the JFrame
frame.getContentPane().add(BorderLayout.EAST, bigpanel);
frame.getContentPane().add(BorderLayout.WEST, boxleft);
frame.getContentPane().add(BorderLayout.SOUTH, bigpanel3);
frame.getContentPane().add(BorderLayout.CENTER, scroll);
}
public void actionPerformed(ActionEvent e) {
}
class phrasemakerListener implements ActionListener{
public void actionPerformed(ActionEvent ev) {
try{
nouns = new ArrayList<String>();
adjectives = new ArrayList<String>();
verbs = new ArrayList<String>();
nouns.add(nounbox1.getText());
nouns.add(nounbox2.getText());//184?
nouns.add(nounbox3.getText());
adjectives.add(adjbox1.getText());
adjectives.add(adjbox2.getText());
adjectives.add(adjbox3.getText());
verbs.add(verbbox1.getText());
verbs.add(verbbox2.getText());
verbs.add(verbbox3.getText());
nounarray = nouns.toArray(new String[nouns.size()]);
adjarray = adjectives.toArray(new String[adjectives.size()]);
verbarray = verbs.toArray(new String[verbs.size()]);
countnoun = nounarray.length;
countadj = adjarray.length;
countverb = verbarray.length;
ran1 = (int) (Math.random() * countverb);
ran2 = (int) (Math.random() * countadj);
ran3 = (int) (Math.random() * countnoun);
funny = adjarray [ran2]+ " " + nounarray [ran3]+" " + verbarray [ran1]+" ";
midgui.append(funny + "\n ");
phrasemaker.setText("Make Another!");
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
class morenounListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
nouns.add(nounbox1.getText());
nounbox1.setText("");
}catch(Exception x){
x.printStackTrace();
}
}
}
class clearnounListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class moreadjListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class clearadjListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class moreverbListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class clearverbListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class savewordsListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
FileOutputStream fileout = new FileOutputStream("words.pb");
ObjectOutputStream out = new ObjectOutputStream(fileout);
out.writeObject(nouns);
out.close();
midgui.append("words saved");
}catch(IOException ex){
ex.printStackTrace();
}
}
}
class savesessionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
FileWriter writer = new FileWriter("PhraseGallery.txt");
writer.write(midgui.getText());
writer.close();
midgui.append("phrase saved");
}catch(IOException x){
x.printStackTrace();
}
}
}
class quick1Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class quick2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class quick3Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class nounbox2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class nounbox3listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class adjbox1Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class adjbox2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class adjbox3Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class verbbox1Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class verbbox2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class verbbox3Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class midguiListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
}
-
June 3rd, 2009, 04:23 AM
#2
Re: NoClassDefFoundError ???????
How did you launch it? What was the Java command line? Remember you must have the directory containing the class file on your classpath.
The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities...
E. Dijkstra
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
June 4th, 2009, 06:10 PM
#3
Re: NoClassDefFoundError ???????
-
June 5th, 2009, 05:46 AM
#4
Re: NoClassDefFoundError ???????
<sigh> 'Huh' is just wasting both our time. If you want help, ask a sensible question.
You said
Today I go to launch it and it gives me this error. Please help!!!!!!!!
The error is telling you the Java runtime can't find the .class file for PhrasebotMac on your classpath. I'm prepared to help, but I need more information, such as answers to the questions I asked.
I don't know how you tried to launch your application, only you know that. If you don't know the answers, you need to find them out, if you don't understand one of the questions, say so and I'll explain or point you to a resource.
Having said that, it sounds to me like you need to learn some Java basics before trying to continue. Try the Java Tutorials.
He who is ashamed of asking is ashamed of learning...
Danish proverb
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|