繁体   English   中英

Eclipse Oxygen Java给出空错误

[英]Eclipse Oxygen Java giving empty error

从理论上讲,我有一些Java从500x500窗口的左上角到右下角画一条线。 编码:

import javax.swing.JComponent;
import javax.swing.JFrame;

import java.awt.*;
import java.awt.geom.*;

@SuppressWarnings("serial")

public class graphix extends JFrame{

    public static void main(String[] args){

        new graphix();
    }

    public graphix(){

        this.setSize(500, 500);

        this.setTitle("Title Here");

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.add(new Draw(), BorderLayout.CENTER);

        this.setVisible(true);

    }


    private class Draw extends JComponent{

        public void paint(Graphics g){

            Graphics2D graph2 = (Graphics2D)g;

            graph2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            Shape drawLine = new Line2D.Float(10, 10, 490, 490);

            graph2.setPaint(Color.BLACK);

            graph2.draw(drawLine);

        }

    }

}

当我运行这段代码时,eclipse给了我错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at graphix.graphix.main(graphix.java:11)

通常在eclipse中,错误消息将显示在这两行之间的空白处,但它表示错误是在第11行触发的,即

public static void main(String[] args){

我的项目名称是graphix,而类文件名是graphix.java

编辑:

还有一个非致命错误:

The declared package "" does not match the expected package "graphix"

触发者:

import javax.swing.JComponent;

文件顶部缺少包声明,它必须与项目中的文件结构匹配:

package xxx.yyy.zzz;

暂无
暂无

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

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