2011-06-17 69 views
4

我有派,而我執行下面的錯誤郵件一個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); 

爲什麼這種類型的錯誤是araise如果有可能戰勝它

+0

你如何運行它們?看起來你的類路徑是錯誤的。 – 2011-06-17 11:51:13

回答

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中的類)。默認情況下,它們位於classpath中。

您必須指定您在類中使用的所有類在

WritableSheet classpath中。從jexcel庫(如果我沒看錯的)。所以,你必須包含這個庫在類路徑中編譯類在運行的類。

你請使用javacjava的-cp選項:

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

./lib/jxl.jar是我所假設的jExcel庫的位置。這是一切,只要確保你在這裏給出正確的道路。

你,如果你使用的是IDE(You should),你必須添加jxl.jar到IDE的類路徑的位置運行類作爲

java -cp ./lib/jxl.jar MyClass 

+0

嗨尼瓦斯,而我執行此cmd下面的錯誤也出現 – Aerrow 2011-06-17 13:13:11

1

你應該編譯/運行時指定正確的類路徑。

1

添加郵件API JAR(可能是郵件的1.4.jar),並在類路徑jExcel jar文件(http://jexcelapi.sourceforge.net/)。

如果你從命令行運行Java代碼..像Java [類名]然後給

java命令郵件1.4.jar; jexcelapi.jar [類名]

否則把這些罐子環境變量CLASSPATH中的文件路徑