我有一個問題,我失去了一個arrayList中的數據。在我調用類MPUComp中的Refresh方法後,我進入mpuChecker類並調用updateTextArea。從arraylist丟失數據
通過這樣做,我失去了MPUComp中arraylist中存在的數據。我做錯了什麼。我認爲這與我如何稱呼這個班有關。我如何正確保存這些數據?
public class MPUComp extends JFrame {
{
private mpuChecker mC;
public ArrayList<String> oldTags = new ArrayList<String>();
public void menu()
{
//...
class MenuActionListener3 implements ActionListener {
public void actionPerformed(ActionEvent e)
{
mC = new mpuChecker();
mC.CheckMpu(path, textField.getText(),1);
setVisible(false);
}
}
class MenuActionListener4 implements ActionListener {
public void actionPerformed(ActionEvent e)
{
mC = new mpuChecker();
mC.CheckMpu(path2, textField_1.getText(),2);
setVisible(false);
}
}
public void refresh(String pane1) {
textArea_1.append(pane1 + "\n");
System.out.println(getOldTags().size());
System.out.println(oldTags.size());
//both print out zero when called second
}
public void updateTextArea(final String text) {
textArea_2.append(text + "\n");
oldTags.add(text);
System.out.println(oldTags.size());
//prints out the correct arraylist size
}
}
}
//second class which calls updateTextArea and refresh
public class mpuChecker {
private MPUComp mC = new MPUComp();
public void CheckMpu(String path, String searchToken, int form)
{
// Print the text to the appropriate text-area either 1 or 2
public void ary1(int path)
{
if(path == 1)
{
for(int l = 0; l < midTags.size(); l++)
{
mC.refresh(midTags.get(l));
}
}
if(path == 2)
{
for(int lk = 0; lk < midTags2.size(); lk++)
{
mC.updateTextArea(midTags2.get(lk));
}
}
}
}
setOldTags()是做什麼的? – jlewis42 2012-02-13 23:35:45
那不重要我刪除了它我試圖使用getters/setters – 2012-02-13 23:38:05
這裏有一堆未定義的變量,例如checkmpu(..)中的midTags;你能否在這些內容上添加細節?我不太瞭解你的代碼,對於您未打印相應方法的方法調用也是如此。 – 2012-02-13 23:43:10