在Cmd提示符中执行时出错

时间:2011-06-17 11:48:54

标签: java

我有一个用于发送邮件的java代码,而我正在执行以下错误显示

.\SendEmail.java:5: package javax.mail.Message does not exist
import javax.mail.Message.RecipientType;
                         ^
.\SendEmail.java:6: package javax.mail.internet does not exist
import javax.mail.internet.AddressException;
                          ^
.\SendEmail.java:7: package javax.mail.internet does not exist
import javax.mail.internet.InternetAddress;
                          ^
.\SendEmail.java:8: package javax.mail.internet does not exist
import javax.mail.internet.MimeMessage;

和另一个用于在数据库中写入一些值的java类,其中将显示以下错误

                           ^
.\WriteHelper.java:34: cannot find symbol
symbol  : class WorkbookSettings
location: class WriteHelper
                WorkbookSettings wbSettings = new WorkbookSettings();
                ^
.\WriteHelper.java:34: cannot find symbol
symbol  : class WorkbookSettings
location: class WriteHelper
                WorkbookSettings wbSettings = new WorkbookSettings();
                                                  ^
.\WriteHelper.java:38: cannot find symbol
symbol  : class WritableWorkbook
location: class WriteHelper
                WritableWorkbook workbook = Workbook.createWorkbook(file, wbSett
ings);
                ^
.\WriteHelper.java:38: cannot find symbol
symbol  : variable Workbook
location: class WriteHelper
                WritableWorkbook workbook = Workbook.createWorkbook(file, wbSett
ings);
                                            ^
.\WriteHelper.java:40: cannot find symbol
symbol  : class WritableSheet
location: class WriteHelper
                WritableSheet excelSheet = workbook.getSheet(0);
                ^
.\WriteHelper.java:51: cannot find symbol
symbol  : class WritableFont
location: class WriteHelper
                WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10
);
                ^
.\WriteHelper.java:51: cannot find symbol
symbol  : class WritableFont
location: class WriteHelper
                WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10
);
                                             ^
.\WriteHelper.java:51: cannot find symbol
symbol  : variable WritableFont
location: class WriteHelper
                WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10
);
                                                          ^
.\WriteHelper.java:53: cannot find symbol
symbol  : class WritableCellFormat
location: class WriteHelper
                times = new WritableCellFormat(times10pt);
                            ^
.\WriteHelper.java:58: cannot find symbol
symbol  : class WritableFont
location: class WriteHelper
                WritableFont times10ptBoldUnderline = new WritableFont(
                ^
.\WriteHelper.java:58: cannot find symbol
symbol  : class WritableFont
location: class WriteHelper
                WritableFont times10ptBoldUnderline = new WritableFont(
                                                          ^
.\WriteHelper.java:59: cannot find symbol
symbol  : variable WritableFont
location: class WriteHelper
                                WritableFont.TIMES, 10, WritableFont.BOLD, false
,
                                ^
.\WriteHelper.java:59: cannot find symbol
symbol  : variable WritableFont
location: class WriteHelper
                                WritableFont.TIMES, 10, WritableFont.BOLD, false
,
                                                        ^
.\WriteHelper.java:60: cannot find symbol
symbol  : variable UnderlineStyle
location: class WriteHelper
                                UnderlineStyle.SINGLE);
                                ^
.\WriteHelper.java:61: cannot find symbol
symbol  : class WritableCellFormat
location: class WriteHelper
                timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderli
ne);
                                         ^
.\WriteHelper.java:65: cannot find symbol
symbol  : class CellView
location: class WriteHelper
                CellView cv = new CellView();
                ^
.\WriteHelper.java:65: cannot find symbol
symbol  : class CellView
location: class WriteHelper
                CellView cv = new CellView();
                                  ^
.\WriteHelper.java:90: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label=new Label(j,k,JavaSamp.date.get(z),timesBold
Underline);
                        ^
.\WriteHelper.java:90: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label=new Label(j,k,JavaSamp.date.get(z),timesBold
Underline);
                                        ^
.\WriteHelper.java:92: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label1=new Label(m,k,JavaSamp.motherboard.get(z),t
imesBoldUnderline);
                        ^
.\WriteHelper.java:92: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label1=new Label(m,k,JavaSamp.motherboard.get(z),t
imesBoldUnderline);
                                         ^
.\WriteHelper.java:94: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label2=new Label(p,k,JavaSamp.processorid.get(z),t
imesBoldUnderline);
                        ^
.\WriteHelper.java:94: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label2=new Label(p,k,JavaSamp.processorid.get(z),t
imesBoldUnderline);
                                         ^
.\WriteHelper.java:96: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label3=new Label(pn,k,JavaSamp.processorname.get(z
),timesBoldUnderline);
                        ^
.\WriteHelper.java:96: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label3=new Label(pn,k,JavaSamp.processorname.get(z
),timesBoldUnderline);
                                         ^
.\WriteHelper.java:98: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label4=new Label(bn,k,JavaSamp.biosname.get(z),tim
esBoldUnderline);
                        ^
.\WriteHelper.java:98: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label4=new Label(bn,k,JavaSamp.biosname.get(z),tim
esBoldUnderline);
                                         ^
.\WriteHelper.java:100: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label5=new Label(bid,k,JavaSamp.biosid.get(z),time
sBoldUnderline);
                        ^
.\WriteHelper.java:100: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label5=new Label(bid,k,JavaSamp.biosid.get(z),time
sBoldUnderline);
                                         ^
.\WriteHelper.java:102: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label6=new Label(bman,k,JavaSamp.biosname.get(z),t
imesBoldUnderline);
                        ^
.\WriteHelper.java:102: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label6=new Label(bman,k,JavaSamp.biosname.get(z),t
imesBoldUnderline);
                                         ^
.\WriteHelper.java:104: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label7=new Label(cval,k,JavaSamp.install_countlist
.get(z),timesBoldUnderline);
                        ^
.\WriteHelper.java:104: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label7=new Label(cval,k,JavaSamp.install_countlist
.get(z),timesBoldUnderline);
                                         ^
.\WriteHelper.java:106: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label8=new Label(8,k,JavaSamp.maxval,timesBoldUnde
rline);
                        ^
.\WriteHelper.java:106: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label8=new Label(8,k,JavaSamp.maxval,timesBoldUnde
rline);
                                         ^
.\WriteHelper.java:108: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label9=new Label(9,k,JavaSamp.maxsysval,timesBoldU
nderline);
                        ^
.\WriteHelper.java:108: cannot find symbol
symbol  : class Label
location: class WriteHelper
                        Label label9=new Label(9,k,JavaSamp.maxsysval,timesBoldU
nderline);
                                         ^
.\WriteHelper.java:117: cannot find symbol
symbol  : class Label
location: class WriteHelper
                Label label;
                ^
.\WriteHelper.java:118: cannot find symbol
symbol  : class Label
location: class WriteHelper
                label = new Label(column, row, s, timesBoldUnderline);

如果有任何可能的错误,为什么会出现这种类型的错误

3 个答案:

答案 0 :(得分:3)

这些是类路径错误。您正在使用的类应该存在于JVM的类路径中。

我们来看下面的例子

.\WriteHelper.java:40: cannot find symbol
symbol  : class WritableSheet
location: class WriteHelper
                WritableSheet excelSheet = workbook.getSheet(0);
                ^

此消息表示:在WriteHelper.java第40行,您指的是类WritableSheet,但编译器无法找到此类的位置。

编译器在classpath中搜索程序中使用的类。 Claspath是编译器和运行时遇到他们“不知道”的类时所看到的路径(目录或jar文件集)。 (他们“知道”的类是那些属于java语言的类(例如java.langjava.math中的类)。默认情况下,这些类在类路径中。

您必须在类路径中指定您在类中使用的所有类。

WritableSheet来自jexcel库(如果我没错)。因此,在运行类时编译类时,必须在类路径中包含此库。

您可以使用javacjava

javac -cp ./lib/jxl.jar MyClass.java

./lib/jxl.jar是我假设的jExcel库的位置。这可以是任何东西,只要确保你在这里给出正确的路径。

您将该课程视为

java -cp ./lib/jxl.jar MyClass

如果您使用的是IDE(You should),则可以将jxl.jar的位置添加到IDE的类路径中。

答案 1 :(得分:1)

编译/运行时应指定正确的类路径。

答案 2 :(得分:1)

在类路径中添加mail api jar(可能是mail-1.4.jar)和jExcel jar文件(http://jexcelapi.sourceforge.net/)。

如果你从命令行运行java代码..比如java [className]那么给

java -cp mail-1.4.jar; jexcelapi.jar [className]

否则将这些jar文件路径放在环境变量CLASSPATH