Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

don't understand this error

  Asked By: Hamish    Date: Aug 28    Category: Java    Views: 953
  

A:\chapt5\FredsApplet.java:113: cannot resolve symbol
symbol : constructor MessageBox
(FredsApplet,java.lang.String,java.lang.String)
location: class MessageBox
errorBox = new MessageBox(this, "Data Entry","Nothing Entered");
^
1 error
---------------------------------------------------------------------
FredsApplet.java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class FredsApplet extends Applet implements ActionListener
{
MessageBox errorBox;
private Button keysArray[];
private Panel keyPad;
private Panel lcdPad;
private Panel buttonPad;
private TextField lcdField;
Panel firstRow = new Panel();
Panel secondRow = new Panel();
Panel thirdRow = new Panel();
Panel fourthRow = new Panel();
Panel fifthRow = new Panel();
Label companyName = new Label("Fred's Foods",Label.CENTER);
Label produceCode = new Label("Enter The Produce Code: ");
TextField produceField = new TextField(10);
Label lblWeight = new Label("Enter the weight: ");
TextField weightField = new TextField(10);
Button CalculateButton = new Button("Calculate");
Button ProduceButton = new Button("Produce Code");
Button WeightButton = new Button("Weight");
Button ClearButton = new Button("Clear");
private int result;
private boolean first;
private boolean foundKey;
static boolean clearText;
Label foodLabel = new Label("");
Choice foodChoice = new Choice();


public void init()
{
lcdField = new TextField(20);
lcdPad = new Panel();
keyPad = new Panel();
buttonPad = new Panel();
keysArray = new Button[10];

setLayout(new BorderLayout());
setBackground(Color.gray);

lcdField.setEditable(false);
lcdPad.add(lcdField);
lcdPad.add(companyName);
lcdPad.add(produceCode);
lcdPad.add(produceField);

for(int i = 0; i<=9; i++)
keysArray[i] = new Button(String.valueOf(i));

keyPad.setLayout(new GridLayout(6,2));

for(int i =0; i<=9; i++)
keyPad.add(keysArray[i]);

buttonPad.add(CalculateButton);
buttonPad.add(ProduceButton);
buttonPad.add(WeightButton);
buttonPad.add(ClearButton);
buttonPad.add(foodChoice);
foodChoice.addItem("Grape(s)");
foodChoice.addItem("Orange(s)");
foodChoice.addItem("Apple(s)");
foodChoice.addItem("Bannana(s)");
foodChoice.addItem("Mango(s)");
foodChoice.addItem("Lemon(s)");
foodChoice.addItem("Brocoli");
foodChoice.addItem("Salad");
foodChoice.addItem("Avocato");
foodChoice.addItem("Tomatoe(s)");

add(lcdPad, BorderLayout.NORTH);
add(keyPad, BorderLayout.CENTER);
add(buttonPad, BorderLayout.SOUTH);


for(int i = 0; i < keysArray.length; i++)
keysArray[i].addActionListener(this);
CalculateButton.addActionListener(this);
ClearButton.addActionListener(this);
ProduceButton.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
foundKey = false;
for(int i = 0; i < keysArray.length && !foundKey;
i++)
if(e.getSource() == keysArray[i])
{
foundKey = true;
switch(i)
{
case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8: case 9:
lcdField.setText(lcdField.getText()+keysArray
[i].getLabel());
break;
}
}
if(e.getSource() == ClearButton)
{
lcdField.setText("");
clearText=false;
}
if(e.getSource() == ProduceButton)
{

if(lcdField.getText().length()==0)
{
errorBox = new MessageBox(this, "Data
Entry","Nothing Entered");
errorBox.setVisible(true);
}
else
result = Integer.parseInt(lcdField.getText
());

if(result == 1111)
{
lcdField.setText("");
lcdField.setText("Code accepted for Grape
(s)");
}
if(result == 1112)
{
lcdField.setText("");
lcdField.setText("Code accepted for Orange
(s)");
}
if(result == 1113)
{
lcdField.setText("");
lcdField.setText("Code accepted for Apple
(s)");
}
if(result == 1114)
{
lcdField.setText("");
lcdField.setText("Code accepted for Mango
(s)");
}
if(result == 1115)
{
lcdField.setText("");
lcdField.setText("Code accepted for Lemon
(s)");
}
}
}
}

----------------------------------------------------------------------
MessageBox.java

import java.awt.*;
import java.awt.event.*;

class MessageBox extends Dialog implements ActionListener
{
private String result;
private Button OKButton;

public MessageBox(Frame frame, String title, String
messageString)
{
//Call Dialog's Constructor
super(frame, title, true);

//determine the size of the message box
Rectangle bounds = frame.getBounds();
setBackground(Color.white);
setLocation(bounds.x + bounds.width/3, bounds.y +
bounds.height/3);


//create a Panel to hold the message
Panel messagePane = new Panel();
Label message = new Label(messageString);
messagePane.add(message);
add(messagePane, BorderLayout.CENTER);

//create a panel to hold the button
Panel buttonPane = new Panel();
OKButton = new Button(" OK ");
buttonPane.add(OKButton);
add(buttonPane, BorderLayout.SOUTH);

//add the action listener to the button
OKButton.addActionListener(this);

//reorganize internal components to fit window
pack();
}

public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
}

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Louis Mason     Answered On: Aug 28

What does this mean?

Exception in thread "main" java.lang.NumberFormationException: For
input string: ""
at java.lang.NumberFormatException.forInputString
(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:489)
at java.lang.Integer.parseInt(Integer.java:518)
at Exer11.main(Exer11.java:31)
Press any key to continue...

 
Answer #2    Answered By: Hehet Chalthoum     Answered On: Aug 28


All sub-classes of RuntimeException class are program bugs. Check your
program.

 
Answer #3    Answered By: Sean Grant     Answered On: Aug 28

Whenever u get a stack trace like this...
always look at the name of the exception name.. which
would tell u the type of error  that occured.. and was
uncaught... and then it gives u the line no., method
and the class name.. where this happened..

in your case, its parseInt() method which is throwing
this error.. which means that the parameter passed to
it for int conversion is invalid...
chk the parameter u are passing to Integer.parseInt()
in your main method.

 
Answer #4    Answered By: Huette Miller     Answered On: Aug 28

It says that an exception has occured when it was trying to convert
a string to int, but it did not found any valid int in string
i.e, "".
In ur code test whether the incomming string is blank or not.

 
Answer #5    Answered By: Maria Miller     Answered On: Aug 28

You tried to input data from JOptionPane window, convert it to integer....
But you pressed cancel instead of OK button... So JOptionPane returns "".
And your program convert it...
That's my guess..

 
Answer #6    Answered By: Elias Turner     Answered On: Aug 28

If I had to guess without seeing the whole code, it would be that
the program is expecting some String that it can convert into a
number, and it can't convert an empty string. Maybe you are trying
to use a value from a TextField and the TextField was blank.

Did you put the code around line 48 in a try-catch block?

That's all I could say since you didn't include your source code.

 
Answer #7    Answered By: Kifah Malik     Answered On: Aug 28

I guess tht's all one could say about the error
without looking code.

well, if ur using a collection class and in one of ur
iteration, you are not having any string value which
represents a number.

to debug
--------

1. Try printing the value of the variable.
2. If u get an empty string, then u might consider
adding a try-catch block as Jim suggested.
3. Parsing a non numeric string value will throw such
this error.

 
Didn't find what you were looking for? Find more on don't understand this error Or get search suggestion and latest updates.




Tagged: