java - eclipse编译时出现未知错误

标签 java swing

public class code extends JFrame{
   /**
    * 
    */
   private static final long serialVersionUID = 1L;
   public boolean flag = true;
   JButton Bill;
   JButton Enter;
   JTextField Items;
   JTextField Amount;
   public java.util.List<String> Item_list = new ArrayList<String>();
   public java.util.List<String> quantity = new ArrayList<String>();

   public code() {
      super("Market");

      setLayout(new FlowLayout());
      do {
         Items = new JTextField("Enter the Item u wish to purchase");
         add(Items);
         Items.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    command(e.getActionCommand());
                }
            }
         );

         Amount = new JTextField("Enter the quantity of the product");
         add(Amount);
         Amount.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    commandInt(e.getActionCommand());
                }
            }
         );
         Bill = new JButton();
         add(Bill);
         Bill.addActionListener(
            new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    flag = false;
                }
            }
         );

      } while(flag);
   }    

   public void command(String userT) {
      try {
         Item_list.add(userT);
      } catch(Exception e){
        System.out.println("what was that");
      }
   }

   public void commandInt(String string) {
      try {
        quantity.add(string);
      } catch(Exception e) {
        System.out.println("what was that");
      }
   }
}

这段代码基本上只是一个系统,您在其中输入项目和金额并将其存储在列表中,但显然有问题,因为它无法编译。此外,当它编译时,它们突出显示了 JTextField 区域。似乎没有明显的问题。

最佳答案

由于您没有指定错误或警告,我将给出一般性答案。

如果您将鼠标悬停在带下划线的单词上,它们将为您提供问题的简要描述。

在 Eclipse 中,您可以使用快捷键 alt + Enter 来获取有关如何解决问题的建议。

如果问题是错误,那么它将突出显示为红色。否则,如果是警告,则会带有黄色下划线。

错误是您编写的代码中的错误,其中警告更多的是好 friend 告诉您修复某些问题的建议。

关于java - eclipse编译时出现未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25097362/

相关文章:

java - 防止 JTable 双击时自动排序

java - 在 JPanel 上的已知坐标处绘制形状

java - Spring JPA hibernate H2

java - 谷歌云端点 EOFException

java - JFrame 在 thread.sleep() 之前未更新

java - 有没有办法知道 JPanel 是否已完成加载其内容?

java - Swing:放置 jTable 和 jButton

java - JPA更新日期时间戳

java - java中的Selenium无法识别类名

java - 远程系统上的 Akka fire-forget 并不传递所有消息