【发布时间】:2022-01-12 13:41:30
【问题描述】:
我正在为 Java 开发人员使用 Eclipse IDE - 2021-12。我在这里处理的代码在所有其他代码编辑器上都可以正常工作,但我无法在这个代码编辑器上运行它。我曾尝试过其他方法来解决此问题,但到目前为止还没有奏效。
image of the problem
the ant debug error
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.time.ZoneId;
import javax.swing.Timer;
public class Main {
public static String GetTime(){
ZoneId zoneid = ZoneId.of("Asia/Ho_Chi_Minh");
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy; HH:mm:ss");
LocalDateTime localtime = LocalDateTime.now(zoneid);
String time = localtime.format(format);
return time;
}
public static void WindowOpen(){
JFrame frame = new JFrame("Time");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(GetTime(),SwingConstants.CENTER);
label.setPreferredSize(new Dimension(300,100));
frame.getContentPane().add(label,BorderLayout.CENTER);
frame.getContentPane().setBackground(Color.decode("#f88379"));
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
Timer timer = new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent a){
label.setText(GetTime());
}
}
);
timer.start();
}
public static void main(String[] args){
WindowOpen();
}
}
【问题讨论】:
-
你遇到了什么错误?
-
我找不到 Eclipse 代码编辑器给我的任何错误,除非我去调试并用 Ant 运行它,它说它无法运行。
-
如果它“说”它“无法运行”,则将确切的错误粘贴到您的问题中。你的代码不是问题,你的设置是。你的问题归结为:“我尝试了这个对很多人有用但对我不起作用的东西。” - 就这样吧。
-
我的猜测是,在某些时候,您的 Run Configurations 列表中还有另一个“Main”类,而该编译后的类仍然位于您的 bin 或 target 文件夹。您需要做的是清理您的项目并强制所有类重新编译。当您使用它时,清除 Run Configurations 列表。请让我知道这是否解决了您的问题。