处学者的简单问题。错误: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
...全文
145 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pzoon 2003-10-15
  • 打赏
  • 举报
回复
谢谢
lynx1111 2003-10-15
  • 打赏
  • 举报
回复
程序没有问题只是要加这个:新建一个a.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>
HTML Test Page
</title>
</head>
<body>
<applet
codebase = "."
code = "ExceptionApplet.class"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>

打开a.htm即可
pzoon 2003-10-15
  • 打赏
  • 举报
回复
,读取I/O错误,说找不到文件
我是复制的路径呀,不可能不对的。
怎么办?
stamp80 2003-10-15
  • 打赏
  • 举报
回复
生成class文件以后,要编写html文件,将这个class引入这个文件,然后以楼上的办法运行。而不能用java这个命令。
starr0110 2003-10-15
  • 打赏
  • 举报
回复
这是一个Applet,要以Applet的方式运行。
试试在命令行输入appletviewer ExceptionApplet
qiyongjun2003 2003-10-15
  • 打赏
  • 举报
回复
不对,应该是没有Main函数,每个可以执行的Java必须有一个main函数
qiyongjun2003 2003-10-15
  • 打赏
  • 举报
回复
classpath设置,帖子太多了,自己找找看。

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧