Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7512441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:52:15+00:00 2026-05-29T23:52:15+00:00

I am having a problem in which I am losing data in an arrayList.

  • 0

I am having a problem in which I am losing data in an arrayList. After I call the method Refresh in class MPUComp I go into the class mpuChecker and call updateTextArea.

By doing this I am losing the data that existed in the arraylist in MPUComp. What I am doing wrong. I think it has to do with how I call the class. How do I correctly keep this data?

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));
    }
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:52:17+00:00Added an answer on May 29, 2026 at 11:52 pm

    Following up on what jpm suggested, to avoid this you could do

    private MPUChecker mC = new MPUChecker();
    

    in MPUComp. That way you only instantiate that mpuchecker once. Both ActionListeners could then use that MPUChecker.

    If you want each ActionListener to have its own MPUChecker, you could move the creation of their listeners into the body of those internal classes, like so

    class MenuActionListener3 implements ActionListener {   
        MPUChecker menu3mC = new mpuChecker();
    
        public void actionPerformed(ActionEvent e)
        {
            menu3mC.CheckMpu(path, textField.getText(),1);
            setVisible(false);
        }
    }
    

    On the other hand, MPUChecker itself might be referring to the wrong MPUComp, since you create one for the MPUChecker at initialisation of that object. Unless that is the intended behavior, you could remove

    private MPUComp mC = new MPUComp();
    

    from MPUChecker, make CheckMPU static and give it an additional parameter: the MPUComp it’s supposed to check.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with Python's subprocess.Popen method. Here's a test script which demonstrates
I am having problem invoking my Log-on action method, which is in a controller
I am having a hard time with this problem which requires a sort of
I'm having a problem compiling an application which uses Core-Plot in debug mode. It
I am having the problem that I cannot select a specific XML node which
I'm having a problem getting access to a database which lives on a remote
I'm having a problem at work in that our app which uses WCF for
Im having a problem with removing non-utf8 characters from string, which are not displaying
I am having a peculiar problem with the order in which FlowLayoutPanels are added
I'm having a weird problem with the following function, which returns a string with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.