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

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

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

问题

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

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

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

  1. public void Dashboard() {
  2. JButton button = new JButton("点击我");
  3. button.addActionListener(this);
  4. JPanel panel = new JPanel();
  5. panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
  6. panel.setLayout(new GridLayout(0, 1));
  7. panel.add(button);
  8. panel.add(label);
  9. frame.add(panel, BorderLayout.CENTER);
  10. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11. frame.setTitle("GUI");
  12. frame.pack();
  13. frame.setVisible(true);
  14. }
  15. public void actionPerformed(ActionEvent e) {
  16. clicks++;
  17. label.setText("点击次数: " + clicks);
  18. }
  19. public static void main(String[] args) {
  20. new Main().Dashboard();
  21. }

}

  1. <details>
  2. <summary>英文:</summary>
  3. 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

  1. 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();

  1. public void Dashboard() {
  2. JButton button = new JButton(&quot;Click Me&quot;);
  3. button.addActionListener(this);
  4. JPanel panel = new JPanel();
  5. panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
  6. panel.setLayout(new GridLayout(0, 1));
  7. panel.add(button);
  8. panel.add(label);
  9. frame.add(panel, BorderLayout.CENTER);
  10. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11. frame.setTitle(&quot;GUI&quot;);
  12. frame.pack();
  13. frame.setVisible(true);
  14. }
  15. public void actionPerformed(ActionEvent e) {
  16. clicks++;
  17. label.setText(&quot;Number of clicks: &quot; + clicks);
  18. }
  19. public static void main(String[] args) {
  20. new Dashboard();
  21. }

}

  1. </details>
  2. # 答案1
  3. **得分**: 1
  4. 将你的类从`Main`重命名为`Dashboard`,并将`public void Dashboard()`更改为`public Dashboard()`,因为它是一个构造函数。
  5. <details>
  6. <summary>英文:</summary>
  7. Rename your class to `Dashboard` from `Main`, and change `public void Dashboard()` to `public Dashboard()` since its a constructor.
  8. </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:

确定