简体   繁体   中英

Eclipse Oxygen Java giving empty error

I have some Java that, in theory, draws a line from the top left corner to the bottom right corner of the 500x500 window. The code:

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

        }

    }

}

When i run this code, eclipse gives me the error:

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

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

normally in eclipse, the error message will be displayed in the empty space between those two lines, but it says the error is triggered at line 11, which is

public static void main(String[] args){

My project name is graphix, and the class file name is graphix.java

EDIT:

There is also a non-fatal error:

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

triggered by:

import javax.swing.JComponent;

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

package xxx.yyy.zzz;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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