Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-21-2002, 05:48 AM   #1
Member (8 bit)
 
Join Date: Feb 2001
Posts: 156
java problem (maybe ultraedit)

ok.... I'm writing 2 diff class files. A dice.java that handles the random numbers and stuff and a diceinterface.java to handle the GUI and other stuff. DiceInterface runs dice. Anyway here is my problem. My program did what I wanted it to but then I realized I was suppose to have some other stuff so I added what I thought I was suppose to have. What are in the comments are what I thought I was suppose to have. but that isn't where it was originally placed. Anyway I put that in and then compiled then compiled the diceinterface.java and when I compiled the diceinterface.java it came back with this.

Quote:
java.lang.NoClassDefFoundError: DiceInterface/java
Exception in thread "main"
Ok so I made the added code in dice comments and recompiled. It is still giving me that error when it is the same as it was when it worked (or so I think). I think this may be some ultraedit problem as I have had problems where it would corrupt the .java file and I would have to resave the backup file as the .java file. But that didn't work here. Any advice.

Dice.java

Code:
public class Dice extends Object{
   private int currentSide;
   private int totalRolls;
   private int average;
   private int sum;
   
   public Dice(){
      currentSide = 0;
      totalRolls = 0;
      average = 0;
      sum = 0;
   }

   public int setCurrentSide(){
      return currentSide;
   }   
   
   public String toString(){
      String str;
      str = "Current Side: " + currentSide + "\n" +
      	    "Total Rolls: " + totalRolls + "\n" +
      	    "Average: " + average + "\n";
      return str;
   }
   
   public void roll(){
      currentSide = (int)(Math.random() * 6) + 1;
      totalRolls++;
      sum += currentSide;
      average = (int) Math.round(sum / totalRolls);
   }
   
   public void reset(){
      currentSide = 0;
      totalRolls = 0;
      sum = 0;
      average = 0;
   }
}

 /*  
   public int getCurrentSide(){
      return currentSide;
   }
   
   public int getTotalRolls(){
      return totalRolls;
   }
   
   public int getAverage(){
      return average;
   }
*/
DiceInterface.java

Code:
import java.awt.*;
import BreezyGUI.*;

public class DiceInterface extends GBFrame{
   Label d1Label = addLabel ("Dice 1", 1, 1, 1, 1);
   Label d1AvgLabel = addLabel ("Average", 1, 3, 1, 1);
   Label d2Label = addLabel ("Dice 2", 2, 1, 1, 1);
   Label d2AvgLabel = addLabel ("Average", 2, 3, 1, 1);
   Label totalRollsLabel = addLabel ("Total Rolls", 3, 1, 2, 1);
   
   /*
   TextArea d1CurrentField = addTextArea (0, 1, 2, 1, 1);
   TextArea d1AvgField = addTextArea (0, 1, 4, 1, 1);
   TextArea d2CurrentField = addTextArea (0, 2, 2, 1, 1);
   TextArea d2AvgField = addTextArea (0, 2, 4, 1, 1);
   TextArea totalRollsField = addTextArea (0, 3, 3, 1, 1);
   */
   
   TextArea displayField = addTextArea ("",5,1,4,4);
   
   Button rollButton = addButton ("Roll Dice", 4, 1, 2, 1);
   Button resetButton = addButton ("Reset", 4, 3, 2, 1);
   
   private Dice d1;
   private Dice d2;
   
   public DiceInterface(){
      d1 = new Dice();
      d2 = new Dice();
      setTitle("Roll'em Boys");
   }
   
   public void buttonClicked (Button buttonObj){
      if (buttonObj == rollButton){
         d1.roll();
         d2.roll();
         displayField.setText("Dice 1 \n" + d1.toString());
         d2DisplayField.setText("Dice 2 \n" + d2.toString());

         //displayField.setText(d2.toString());
      }
      if (buttonObj == resetButton){
   	 d1.reset();
   	 d2.reset();
      }
   }

   public static void main (String[] args){
      Frame frm = new DiceInterface();
      frm.setSize (400, 400);
      frm.setVisible (true);
   }
}
Thanks

Josh

(hope you can understand what I'm talking about)
minutrice is offline   Reply With Quote
Old 03-21-2002, 12:27 PM   #2
Member (13 bit)
 
DrZaius's Avatar
 
Join Date: Jul 2000
Location: Fullerton, CA
Posts: 7,030
Hi Josh,

Were you able to compile the code before? I have not used UltraEdit before but my guess is that you have to set the Java compile/run tool settings before you can compile. I ask because it looks like "DiceInterface/java" should be "DiceInterface.java" and the compiler is looking for the first file (which doesn't exist, hence the "main" error).
__________________
"A witty saying proves nothing." - Voltaire
DrZaius is offline   Reply With Quote
Old 03-21-2002, 12:37 PM   #3
Registered User
 
c-learner's Avatar
 
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
in the DiceInterface.java
why are you import import BreezyGUI.*;
should it be Dice???? and also you should import javax.swing.*; into DiceInterface...

and the main's wrong;; should be as follow
Code:
public static void main (String[] args){
      DiceInterface frm = new DiceInterface();
      frm.setSize (400, 400);
      frm.setVisible (true);
}

Last edited by c-learner; 03-21-2002 at 12:48 PM.
c-learner is offline   Reply With Quote
Old 03-21-2002, 12:42 PM   #4
Registered User
 
c-learner's Avatar
 
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
try this
Code:
import java.io.*;

public class Dice extends Object{
   private int currentSide;
   private int totalRolls;
   private int average;
   private int sum;
   
   public Dice(){
      currentSide = 0;
      totalRolls = 0;
      average = 0;
      sum = 0;
   }

   public int setCurrentSide(){
      return currentSide;
   }   
   
   public String toString(){
      String str;
      str = "Current Side: " + currentSide + "\n" +
      	    "Total Rolls: " + totalRolls + "\n" +
      	    "Average: " + average + "\n";
      return str;
   }
   
   public void roll(){
      currentSide = (int)(Math.random() * 6) + 1;
      totalRolls++;
      sum += currentSide;
      average = (int) Math.round(sum / totalRolls);
   }
   
   public void reset(){
      currentSide = 0;
      totalRolls = 0;
      sum = 0;
      average = 0;
   }
}

 /*  
   public int getCurrentSide(){
      return currentSide;
   }
   
   public int getTotalRolls(){
      return totalRolls;
   }
   
   public int getAverage(){
      return average;
   }
*/
Code:
import java.awt.*;
import javax.swing.*;

public class DiceInterface extends JFrame{
   Label d1Label = addLabel ("Dice 1", 1, 1, 1, 1);
   Label d1AvgLabel = addLabel ("Average", 1, 3, 1, 1);
   Label d2Label = addLabel ("Dice 2", 2, 1, 1, 1);
   Label d2AvgLabel = addLabel ("Average", 2, 3, 1, 1);
   Label totalRollsLabel = addLabel ("Total Rolls", 3, 1, 2, 1);
   
   /*
   TextArea d1CurrentField = addTextArea (0, 1, 2, 1, 1);
   TextArea d1AvgField = addTextArea (0, 1, 4, 1, 1);
   TextArea d2CurrentField = addTextArea (0, 2, 2, 1, 1);
   TextArea d2AvgField = addTextArea (0, 2, 4, 1, 1);
   TextArea totalRollsField = addTextArea (0, 3, 3, 1, 1);
   */
   
   TextArea displayField = addTextArea ("",5,1,4,4);
   
   Button rollButton = addButton ("Roll Dice", 4, 1, 2, 1);
   Button resetButton = addButton ("Reset", 4, 3, 2, 1);
   
   private Dice d1;
   private Dice d2;
  
   public DiceInterface(){
      setTitle("Roll'em Boys");
      d1 = new Dice();
      d2 = new Dice();
      
   }
   
   public void buttonClicked (Button buttonObj){
      if (buttonObj == rollButton){
         d1.roll();
         d2.roll();
         displayField.setText("Dice 1 \n" + d1.toString());
         d2DisplayField.setText("Dice 2 \n" + d2.toString());

         //displayField.setText(d2.toString());
      }
      if (buttonObj == resetButton){
   	 d1.reset();
   	 d2.reset();
      }
   }

   public static void main (String[] args){
      Frame frm = new DiceInterface();
      frm.setSize (400, 400);
      frm.setVisible (true);
   }
}

Last edited by c-learner; 03-21-2002 at 12:47 PM.
c-learner is offline   Reply With Quote
Old 03-21-2002, 06:13 PM   #5
Member (8 bit)
 
Join Date: Feb 2001
Posts: 156
Hey thanks for the help guys.... I have UltraEdit set up right. I've been using it all semester. It just does crazy stuff sometimes?!?!? Ugh!

I am importing BreezyGUI b/c I'm using it to write the GUI. It's some crap that's in our book. The main method is correct. It is suppose to be
Frame frm = new DiceInterface();

I will try deleting those *.java files and retype them as completely new files they way I have the code written down (it worked the first time). Thanks for the help guys.

Josh
minutrice is offline   Reply With Quote
Old 03-21-2002, 08:49 PM   #6
Registered User
 
c-learner's Avatar
 
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
one question, what version of Java are you learning???
c-learner is offline   Reply With Quote
Old 03-21-2002, 11:00 PM   #7
Member (8 bit)
 
Join Date: Feb 2001
Posts: 156
ummm maybe something like 1.3.1 or something like that. Not for sure exactly. The BreezyGUI is not from java. It is classes written by the author of the text book we are using (I think he did. Don't really know) but they come on a cd with the book or you can download them from the internet.

Anyway.... I did what I said and just deleted those files and made 2 new ones with the same info and it worked. UltraEdit just did something to those files. Now I've completely gotten the program written.

Thanks for the help guys.

Josh
minutrice is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:53 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2