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 7828943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:33:17+00:00 2026-06-02T10:33:17+00:00

I am having some trouble with passing data of an array from one class

  • 0

I am having some trouble with passing data of an array from one class to the next.

edits
I am now no longer getting the error, and my code compiles, but as I had been warned, I got null for every element of the array. Now that I have taken out the static modifiers though, it still gives me null. I have also updated the code.

Here is the class where the array is created.

public class AssignSeat {

String[] arrangement = new String[12];

public void SeatStart() {

    arrangement[0] = "Collins";
    arrangement[2] = "Faivre";
    arrangement[3] = "Kinnard";
    arrangement[6] = "Morgans";
    arrangement[7] = "Rohan";
    arrangement[8] = "Shatrov";
    arrangement[9] = "Sword";
    arrangement[11] = "Tuckness";

    System.out.format("%-15s%-15s%n", "seat", "passenger");

    for (int i=0; i<arrangement.length; i++) {
        System.out.format("%-15s%-15s%n", i+1, arrangement[i]);

    }

}

public String[] getArrangement() {
    return arrangement;
}

public void setArrangement(String[] arrangement) {
    this.arrangement = arrangement;
}
}

and here is the method trying to access the information. It is specifically the for loop that I need help with so Ignore other areas where there are mistakes. Thank you.

public void actionPerformed(ActionEvent event) {
    Scanner scanner = new Scanner(System.in);
    AssignSeat seat = new AssignSeat();

    if(event.getSource() instanceof JButton){

        JButton clickedButton = (JButton) event.getSource();
        String buttonText = clickedButton.getText();

        if (buttonText.equals("first class")) {
            entername.setVisible(true);
            seatnum.setVisible(true);
            confirmed.setVisible(true);
            inputline.setVisible(true);
            outputline.setVisible(true);
            if ((seat.arrangement[1] == null)) {
                System.out.println(seat.arrangement[0]);
                System.out.println(seat.arrangement[2]);
                two.setForeground(Color.green);
            }
        } else if (buttonText.equals("coach")) {
            //System.out.println("so does this!");
            entername.setVisible(true);
            seatnum.setVisible(true);
            confirmed.setVisible(true);
            inputline.setVisible(true);
            outputline.setVisible(true);
            if ((seat.arrangement[4] == null)) {
                five.setForeground(Color.green);
            } 
            if ((seat.arrangement[5] == null)) {
                six.setForeground(Color.green);
            } 
            if ((seat.arrangement[10] == null)) {
                eleven.setForeground(Color.green);
            } 
        }
    }

}
  • 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-06-02T10:33:18+00:00Added an answer on June 2, 2026 at 10:33 am

    The problem lies in the fact that the array was declared as static, but the initialization code for it is in the constructor. Remove all the static modifiers in the original code, and replace this part:

    if (AssignSeat.getArrangement()[1].equals("null"))
    

    With this:

    AssignSeat assign = new AssignSeat();
    if (assign.getArrangement()[1] == null)
    

    Also notice that "null" is not a null value, use null (without quotes) for that.

    A different approach would be to leave the array as an static member, but initialize it statically, like this:

    private static String[] arrangement = new String[12];
    static {
        arrangement[0] = "Collins";
        arrangement[2] = "Faivre";
        arrangement[3] = "Kinnard";
        arrangement[6] = "Morgans";
        arrangement[7] = "Rohan";
        arrangement[8] = "Shatrov";
        arrangement[9] = "Sword";
        arrangement[11] = "Tuckness";
    }
    

    In that case, this would work:

    if (AssignSeat.getArrangement()[1] == null)
    

    But I still believe that making the array static is going to be problematic if several instances of the class happen to be modifying its contents.

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

Sidebar

Related Questions

Hi i am having some trouble passing variables/doing functions from other classes, Right now
I am having trouble passing data from one activity to another. I can easily
I'm having trouble passing a variable defined in one class instance to another class
I'm new to ASP.NET MVC; something I'm having trouble with is getting data from
I'm having some trouble with Java's Calendar. I'm parsing some data from a txt
I'm having some trouble passing a number as an argument for a method: -
I'm having some trouble parsing a JSON that I obtain from my DB to
I'm using the jQuery Countdown plugin but having some trouble getting it to show
I'm not sure why, but I'm having trouble passing a data object (NSManagedObject) to
I'm having some trouble getting bash to play nicely with parsing words off the

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.