当我尝试编译代码时出现此错误。我不确定它有什么问题,我不明白错误是什么。这是错误消息,后面跟着它说错误的行:
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at g52gui.C_login.<clinit>(C_login.java:9)
at g52gui.V_login.<init>(V_login.java:6)
at g52gui.V_login$4.run(V_login.java:181)
...
以及错误的行:
line 9 C_login (controller): private static final C_home controller_home = new C_home();
line 6 V_login (view): private final C_login controller_login = new C_login();
line 181 V_login (view): new V_login().setVisible(true);
似乎问题来自C_home,但那里没有编译错误。
修改
我认为问题可能在这里,在C_login中:
public class C_login {
private static final V_login view_login = new V_login();
private static final M_login model_login = new M_login();
private final static C_home controller_home = new C_home();
private static final C_registration controller_regi = new C_registration();
private static final MySQLAccess sql_connection = new MySQLAccess();
public static void main(String[] args) throws Exception {
view_login.setVisible(true);
}
public static boolean login_button_clicked(String usrn, String psw){
String login = M_login.login(usrn, psw);
if (login == "ok"){
controller_home.start_view(usrn);
view_login.setVisible(false);
} else if (login == "fail" ) {
view_login.error_login();
return false;
} else {
view_login.error_connection();
return false;
}
return false;
}
我将C_home controller_home视为静态,以便稍后可以访问它。是否还有另一种方法可以解决这个问题?
修改
这是C_Home中的初始化程序:
public class C_home {
private static final V_home view_home = new V_home();
private static final M_home model_home = new M_home();
private String username = "";
/* attributes for 3d model */
private BranchGroup sceneBranchGroup = null;
private RotationInterpolator rotator = null;
private Canvas3D offScreenCanvas3D = null;
private ImageComponent2D imageComponent = null;
private static final int offScreenWidth = 200;
private static final int offScreenHeight = 200;