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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:59:05+00:00 2026-06-08T15:59:05+00:00

I have a class with an array as an instance variable/field, which is passed

  • 0

I have a class with an array as an instance variable/field, which is passed through from another class to the first method in this one.
I was under the impression that I should also be able to access it from another method without also passing it to that method but when I try, I get an NPE.

Here’s the code:

public class PLoop {

    // instance variable
    public Memory[] memList;

    // method 1
    public void memPass(Memory[] memLocList) {

        memList = memLocList;
        System.out.println(memList.length);
    }

    // method 2
    public void accessArray() {

        System.out.println(memList.length);
    }
}

When the first method is called I get an integer printed to the console representing the length of the array but when the second method is called it’s NPE, suggesting not the same array.

The second method is called by clicking a button on a GUI. The method associated with this button only has a call along the lines of:

PLoop.accessArray();

Can anyone tell from this what I’m doing wrong?

-EDIT-
The calls to these methods come from two different classes, each of which declares an instance of PLoop:

proc = new PLoop();
  • 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-08T15:59:09+00:00Added an answer on June 8, 2026 at 3:59 pm

    The Methods in your PLoop classes are not static
    Still you are calling PLoop.accessArray();

    Can u please tell what is the real Scenario?

    Just like @Jon Skeet told the code seems to be fine.The only possibility is that you may be
    executing them out of sequence or you may be messing up with memLocList after the first
    method is called.

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

Sidebar

Related Questions

I have a method which takes an array as a parameter from another class:
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
There's this instance variable in my objective-c class: ALuint source; I need to have
Say I have: class DecisionTree(private val instances: Array[Instance]){ and I want to calculate another
I have a Ruby class. I want to get an instance variable from an
So i have a class name repository which is just a simple array.Here is
I have a class with a custom each-method: class CurseArray < Array def each_safe
Does Scala have a version of Rubys' each_slice from the Array class?
I have a helper class that is passed an array of values that is
we have one class which has one float[] and one int[] . Sometimes 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.