2016-09-08 37 views
0

我是新手。我在一個java源文件中遇到了一個簡單的問題:行System.out.pritln(...)已被視爲錯誤的表達式。下面的代碼片段: 「Arrgh」Eclipse中的奇怪行爲3.8.1

package vk.gui; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.util.Properties; 

import com.itextpdf.text.BadElementException; 
import com.itextpdf.text.Chunk; 
import com.itextpdf.text.Document; 
import com.itextpdf.text.DocumentException; 
import com.itextpdf.text.Font; 
import com.itextpdf.text.Image; 
import com.itextpdf.text.PageSize; 
import com.itextpdf.text.Paragraph; 
import com.itextpdf.text.Rectangle; 
import com.itextpdf.text.pdf.BarcodeEAN; 
import com.itextpdf.text.pdf.BaseFont; 
import com.itextpdf.text.pdf.PdfContentByte; 
import com.itextpdf.text.pdf.PdfPCell; 
import com.itextpdf.text.pdf.PdfPCellEvent; 
import com.itextpdf.text.pdf.PdfPTable; 
import com.itextpdf.text.pdf.PdfWriter; 


public class MatrixSheet1 { 
    Properties p; 
    File file; 
    Document document; 
    PdfWriter writer; 
    Image logo = null; 
    Image EANimg = null; 
    float mnoz = new Double(72/25.6).floatValue(); 

    int IMG_WIDTH= new Double(35*mnoz).intValue(); 
    int IMG_HEIGHT=new Double(35*mnoz).intValue(); 
    String err=p.getProperty("cell.height"); 
    System.out.println("Arrgh!"); ///-------------->ERROR! 
    float cell_Height = Float.parseFloat(p.getProperty("cell.height"))*mnoz; 
    float cell_Width = Float.parseFloat(p.getProperty("cell.width"))*mnoz; 

報告的錯誤是在這條線

多個標記

  • 語法錯誤令牌 「」,刪除此令牌

  • 令牌上的語法錯誤,放錯位置的構造(s)

sout和sysout快捷方式都不起作用。在相同包的其他現有源文件中,一切正常,快捷方式工作並且表達式不會觸發錯誤。 我試圖創建另一個源文件並複製/粘貼內容,但我得到了同樣的錯誤。什麼和哪裏出了問題? 我需要打印只是爲了調試,但這有點惱人的症狀。 在此先感謝。

+0

我會嘗試刪除該行並重新鍵入它。有時,不可見的字符被錯誤地插入並破壞文件。 –

+0

您正在嘗試在只允許使用排序和初始化的代碼區域執行語句。 – f1sh

回答

2

發生這種情況是因爲您只能在方法內部使用System.out.println()。如果你想這樣做,它會工作:

public class MatrixSheet1 { 
    Properties p; 
    File file; 
    Document document; 
    PdfWriter writer; 
    Image logo = null; 
    Image EANimg = null; 
    float mnoz = new Double(72/25.6).floatValue(); 

    int IMG_WIDTH= new Double(35*mnoz).intValue(); 
    int IMG_HEIGHT=new Double(35*mnoz).intValue(); 
    String err=p.getProperty("cell.height"); 
    systemMessage("Argh!"); 
    float cell_Height = Float.parseFloat(p.getProperty("cell.height"))*mnoz; 
    float cell_Width = Float.parseFloat(p.getProperty("cell.width"))*mnoz; 


    private void systemMessage(String message){ 
     System.out.println(message); 
    } 

} 
+0

是的,你懂了!首先嚐試我得到硬編碼值,所以我沒有必要調試它。在第二階段,我嘗試使用屬性文件中的參數來使用參數,忘記了我實際上代碼的哪一部分。非常感謝。 – Cornel