简体   繁体   English

NoClassDefFoundError:在appletviewer中运行applet时出错

[英]NoClassDefFoundError: Error in running applet in appletviewer

I just ran into trouble in applet execution in webpage: An error dialog popped up: 我只是在网页中执行applet时遇到麻烦:弹出错误对话框: 在此处输入图片说明

The calculator is my class name and Exercise4 is the folder that contains it. 计算器是我的班级名称,exercise4是包含它的文件夹。 I am sure that the html file and the calculator.class are in the same folder named Exercise4. 我确定html文件和Calculator.class位于同一个名为Exercise4的文件夹中。 What is happening in here? 这里发生了什么?

You are mixing up directories and packages. 您正在混合目录和软件包。 If you class has the name x and resides in the package y your codebase must not point to the directory y . 如果您的类的名称为x且位于包y您的代码库不得指向目录y Instead the codebase must point to the parent directory of y and the class name must be specified as yx . 相反,代码库必须指向y父目录 ,并且类名称必须指定为yx

So in your case you seem to have specified a directory Exercise4 which ought to be the package name and an applet class of calculator which is wrong as it ignores the package name. 因此,在您的情况下,您似乎已经指定了一个目录Exercise4 ,它应该是软件包名称,而calculator的applet类却是错误的,因为它忽略了软件包名称。

As said you have to specify the parent directory of the package directory structure, ie the parent directory of Exercise4 , as the codebase and specify Exercise4.calculator as the applet class. 如前所述,您必须指定包目录结构的父目录(即Exercise4的父目录)作为代码库,并指定Exercise4.calculator作为applet类。

Note that package names should be lowercase and class names be uppercase by convention. 请注意,按照惯例,程序包名称应小写,类名称应大写。 Adhering to conventions helps other people help you on problems, eg by finding the problem faster. 遵守约定可以帮助其他人解决问题,例如更快地找到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM