尝试运行我的程序时,我不断收到此错误。
Exception in thread "main" java.lang.StackOverflowError
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:244)
at javax.swing.UIDefaults.getUI(UIDefaults.java:752)
at javax.swing.UIManager.getUI(UIManager.java:1001)
at javax.swing.JPanel.updateUI(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:69)
at javax.swing.JPanel.<init>(JPanel.java:92)
at javax.swing.JPanel.<init>(JPanel.java:100)
at serverProperties.<init>(serverProperties.java:164)
at exportProperties.<init>(exportProperties.java:8)
at serverProperties.<init>(serverProperties.java:162)
它仅在尝试从某个类访问方法后发生。
这是主要课程:
public class serverProperties extends JPanel
{
//Add classes
exportProperties writeProperties = new exportProperties();
//Assume I created the array sent to the exportProperties class
public serverProperties()
{
CheckBoxListener checkListener = new CheckBoxListener();
//Assume I created the check box and added the listener for it
}
private class CheckBoxListener implements ItemListener
{
public void itemStateChanged (ItemEvent event)
{
JCheckBox checkBox;
checkBox= (JCheckBox)event.getSource();
//Process check Boxes
if (checkBox.isSelected())
{
checkBox.setText("Yes");
writeProperties.exportFile(propertiesArr);
}
}
}
}
这是上面代码访问的类的代码:
public class exportProperties extends serverProperties
{
public void exportProperties(String[] args)
{
exportFile(args);
}
public static void exportFile(String[] propertiesArr)
{
try
{
FileWriter outFile = new FileWriter("Path/file.txt");
BufferedWriter out = new BufferedWriter(outFile);
//Loop through properties
for (int i=0; i < 27; i++)
{
out.append(propertiesArr[i]);
}
//out.write("Test");
out.close();
}
catch (IOException exception)
{
exception.printStackTrace();
}
}
public void importFile()
{
}
}
一旦我删除了对 exportProperties 类的调用,程序就会完美运行。带有错误消息,最后两行
at exportProperties.<init>(exportProperties.java:8)
at serverProperties.<init>(serverProperties.java:162)
他们在它结束之前重复了很多次。
我已经用谷歌搜索了,然后用谷歌搜索,我不知道发生了什么..感谢您的帮助!