minutrice
03-21-2002, 06:48 AM
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.
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
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
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)
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
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
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)