PDA

View Full Version : java problem (maybe ultraedit)


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)

DrZaius
03-21-2002, 01:27 PM
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).

c-learner
03-21-2002, 01:37 PM
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

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

c-learner
03-21-2002, 01:42 PM
try this

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;
}
*/


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);
}
}

minutrice
03-21-2002, 07:13 PM
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

c-learner
03-21-2002, 09:49 PM
one question, what version of Java are you learning???

minutrice
03-22-2002, 12:00 AM
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