简体   繁体   English

Eclipse 3.8.1中的奇怪行为

[英]Strange Behaviour in Eclipse 3.8.1

I'm a newbie here. 我是这里的新手。 I have a simple problem in ONE java source file: the row System.out.pritln(...) has been treated as an erroneous expression. 我在一个Java源文件中有一个简单的问题: System.out.pritln(...)行已被视为错误的表达式。 Here's the code snippet: 这是代码片段:

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;

The reported error is 报告的错误是

Multiple markers at this line 这行有多个标记

  • Syntax error on token ""Arrgh!"", delete this token 令牌““ Arrgh!”“的语法错误,请删除此令牌

  • Syntax error on token(s), misplaced construct(s) 令牌语法错误,构造放置错误

The sout and sysout shortcuts do not work neither. sout和sysout快捷方式都不起作用。 In other existing source files of same package everything is OK, the shortcuts work and the expression does not trigger an error. 在相同程序包的其他现有源文件中,一切正常,快捷方式有效,并且表达式不会触发错误。 I tried to create another source file and copy/paste the content, but I got the same error. 我试图创建另一个源文件并复制/粘贴内容,但是遇到了同样的错误。 What and where went wrong? 什么地方和哪里出了问题? I need the printing just for debugging, but this is a bit annoying symptom. 我只需要打印即可进行调试,但这是一个令人讨厌的症状。 Thanks in advance. 提前致谢。

This happens because you can use System.out.println() only inside methodes. 发生这种情况是因为您只能在方法内部使用System.out.println()。 If you would do something like this, it would work: 如果您要做这样的事情,它将起作用:

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);
    }

}

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

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