处学者的简单问题。错误:Exception in thread "main" java.lang.NosuchMethodError:main,带原码;
pzoon 2003-10-15 03:15:16 工具:JCreator 文件名:ExceptionApplet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ExceptionApplet extends Applet implements ActionListener
{
Label L1,L2;
TextField tf1,tf2;
String answerStr;
double d1,d2;
public void init()
{
L1 = new Label("请输入0到100之间的整数");
add(L1);
tf1 = new TextField(6);
add(tf1);
tf2 = new TextField(6);
add(tf2);
L2 = new Label("两数相除的结果:");
add(L2);
tf1.addActionListener(this);
tf2.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
try
{
d1 = Double.valueOf(tf1.getText()).doubleValue();
d2 = Double.valueOf(tf2.getText()).doubleValue();
//valueOf(String s)可能抛出异常NumberFormatException
L2.setText("两数相除的结果:"+Result());
//调用Result()方法可能会抛出NumberRangException异常
}
catch(NumberFormatException e)
{
answerStr = "输入的必须是数字";
L2.setText(answerStr);
}
catch(NumberRangException ee)
{
answerStr = ee.getMessage();
L2.setText(answerStr);
}
repaint();
}
public double Result() throws NumberRangException
{
double answer = 0;
try
{
if((d1<0)||(d2<0)||(d1>100)||(d2>100))
{
NumberRangException ee = new NumberRangException("输入的数字不在指定的范围!请从新输入");
throw ee;
}
answer = d1/d2;
}
catch(ArithmeticException eee)
{
answerStr = eee.toString();
}
return answer;
}
}
class NumberRangException extends Exception
{
NumberRangException(String msg)
{
super(msg);
}
//子类调用父类带参数的构造函数
}
错误如下:
Exception in thread "main" java.lang.NosuchMethodError:main