簡體   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