我正在尝试创建大量 JTextField 对象,但由于某种原因,我的代码无法编译。我已经玩了太久了,我找不到任何让编译器生气的好理由;这是我的代码,只有一个长度为 2 的数组:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class SUDOKU_temp extends JApplet
{
//declare fields
public JTextField[] fields = new JTextField[2];
fields[0] = new JTextField();
fields[1] = new JTextField();
//other stuff happens down here that the compiler is ok with
}
如果我只运行长度为 1 的数组的代码,我会得到完全相同的错误,它们是:
linux63:~demo$ ./compile
SUDOKU_temp.java:11: ']' expected
fields[0] = new JTextField();
^
SUDOKU_temp.java:11: ';' expected
fields[0] = new JTextField();
^
SUDOKU_temp.java:11: illegal start of type
fields[0] = new JTextField();
^
SUDOKU_temp.java:11: <identifier> expected
fields[0] = new JTextField();
^
SUDOKU_temp.java:11: ';' expected
fields[0] = new JTextField();
^
SUDOKU_temp.java:11: illegal start of type
fields[0] = new JTextField();
^
SUDOKU_temp.java:11: <identifier> expected
fields[0] = new JTextField();
^
我觉得这是编译器的问题,而不是代码的问题,任何有关如何调试的帮助将不胜感激。提前致谢!!