Compile Error 无法找到符号 new Dashboard(); ^ 符号:类 Dashboard 位置:类 Main 1

huangapple go评论58阅读模式
英文:

Compile Error cannot find symbol new Dashboard(); ^ symbol: class Dashboard location: class Main 1

问题

所以我尝试编译这个程序,但我一直收到错误消息

Main.java:39: 错误: 无法找到符号
new Dashboard();
^
符号: 类 Dashboard
位置: 类 Main
1 错误

我尝试查看其他类似的帖子,尝试了他们正在做的事情,但对我都不起作用。所以我想重新安装我的Java安装程序会起作用(从jdk7升级到jdk13),但我得到了相同的结果。我觉得自己很愚蠢,要问的可能是一个非常容易忽视的问题,但我一无所知。帮助我


import javax.swing.;
import java.awt.
;
import java.awt.event.*;

public class Main implements ActionListener {
private int clicks = 0;
private JLabel label = new JLabel("点击次数: 0 ");
private JFrame frame = new JFrame();

public void Dashboard() {

   
    JButton button = new JButton("点击我");
    button.addActionListener(this);

    
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
    panel.setLayout(new GridLayout(0, 1));
    panel.add(button);
    panel.add(label);

    
    frame.add(panel, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("GUI");
    frame.pack();
    frame.setVisible(true);
}


public void actionPerformed(ActionEvent e) {
    clicks++;
    label.setText("点击次数:  " + clicks);
}


public static void main(String[] args) {
    new Main().Dashboard();
}

}


<details>
<summary>英文:</summary>

So I&#39;m trying to compile this program but I keep getting the error

Main.java:39: error: cannot find symbol
new Dashboard();
^
symbol: class Dashboard
location: class Main
1 error

I&#39;ve tried looking at other similar posts trying out what they&#39;re doing but none of that worked for me. So I figured reinstalling my java installation would work (from jdk7 to jdk13), but I got the same results. I feel so stupid to ask what is probably a very easy oversight but I&#39;m clueless. help me


import javax.swing.;
import java.awt.
;
import java.awt.event.*;

public class Main implements ActionListener {
private int clicks = 0;
private JLabel label = new JLabel("Number of clicks: 0 ");
private JFrame frame = new JFrame();

public void Dashboard() {

   
    JButton button = new JButton(&quot;Click Me&quot;);
    button.addActionListener(this);

    
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
    panel.setLayout(new GridLayout(0, 1));
    panel.add(button);
    panel.add(label);

    
    frame.add(panel, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle(&quot;GUI&quot;);
    frame.pack();
    frame.setVisible(true);
}


public void actionPerformed(ActionEvent e) {
    clicks++;
    label.setText(&quot;Number of clicks:  &quot; + clicks);
}


public static void main(String[] args) {
    new Dashboard();
}

}




</details>


# 答案1
**得分**: 1

将你的类从`Main`重命名为`Dashboard`,并将`public void Dashboard()`更改为`public Dashboard()`,因为它是一个构造函数。

<details>
<summary>英文:</summary>

Rename your class to `Dashboard` from `Main`, and change `public void Dashboard()` to `public Dashboard()` since its a constructor.

</details>



huangapple
  • 本文由 发表于 2020年7月30日 10:55:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63165494.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定