我正在Netbeans中编写一个可视化应用程序,并且需要一个对话框。我决定从Netbeans自动提供的AboutBox
中复制代码段,但却发现这两个代码都会导致错误!
我似乎无法找到错误的来源,尽管两者都是在对话框关闭时引起的。
为简单起见,我认为两个错误都是相关的,这是我的Dialog
。为简洁起见,我省略了initComponents()
和main(从未调用过)方法,但defaultCloseOperation为DISPOSE_ON_CLOSE
。
运行时我得到一个堆栈溢出,我将在下面发布。
public class AddRecipe extends javax.swing.JDialog {
/** Creates new form AddRecipe */
public AddRecipe(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
AddRecipe(java.awt.Frame parent) {
super(parent);
initComponents();
}
private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {
dispose();
}
// Variables declaration - do not modify
private javax.swing.JLabel Serves;
private javax.swing.JButton acceptButton;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField nameTextField;
private javax.swing.JTextField servesTextField;
private javax.swing.JTextField timeTextField;
// End of variables declaration
}
堆栈追踪:
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:262)
at java.beans.Statement.invokeInternal(Statement.java:257)
at java.beans.Statement.access$000(Statement.java:56)
at java.beans.Statement$2.run(Statement.java:158)
at java.security.AccessController.doPrivileged(Native Method)
at java.beans.Statement.invoke(Statement.java:154)
at java.beans.Expression.getValue(Expression.java:115)
at java.beans.Encoder.getValue(Encoder.java:105)
at java.beans.Encoder.get(Encoder.java:225)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:110)
at java.beans.Encoder.writeObject(Encoder.java:74)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:274)
at java.beans.Encoder.writeExpression(Encoder.java:304)
at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:389)
at java.beans.DefaultPersistenceDelegate.doProperty(DefaultPersistenceDelegate.java:229)
at java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:264)
at java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java:408)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:116)
at java.beans.Encoder.writeObject(Encoder.java:74)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:274)
at java.beans.Encoder.writeExpression(Encoder.java:304)
at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:389)
at java.beans.DefaultPersistenceDelegate.doProperty(DefaultPersistenceDelegate.java:229)
at java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:264)
at java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java:408)
(堆栈跟踪重复几百次)。
为了完整起见,这是调用Dialog的函数。同样,此代码是根据默认的Netbeans行为建模的(即使提供的AboutBox Netbeans导致java.lang.reflect.InvocationTargetException
)。
private void newRecipeItemActionPerformed(java.awt.event.ActionEvent evt) {
if (addRecipe == null) {
JFrame mainFrame = RecipesApp.getApplication().getMainFrame();
addRecipe = new AddRecipe(mainFrame);
addRecipe.setLocationRelativeTo(mainFrame);
}
RecipesApp.getApplication().show(addRecipe);
}
答案 0 :(得分:0)
正如Ashton K在评论中提到的那样,这个问题可以通过迁移到JDK的Oracle版本来解决。所以这个问题至少要运行他特定版本的OpenJDK。