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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:11:46+00:00 2026-06-18T16:11:46+00:00

I am trying to create a constructor for a class // Variables to send

  • 0

I am trying to create a constructor for a class

// Variables to send to Host
private class ParameterClass {
  public String parameter;
  public int value;
  public Boolean sended;
}

public class SendToHostClass {
  private int sizeBuffer;
  public ParameterClass[] parameterList;

  SendToHostClass(int sizeBufferConf) {
    sizeBuffer = sizeBufferConf;
    parameterList = new ParameterClass[sizeBuffer];
  }

  public void Put (String parameter, int valuePut, Boolean sendedPut) {
    for (int index=0; index<sizeBuffer; index++) {
      if (parameter == parameterList[index].parameter) {
        parameterList[index].value = valuePut;
        parameterList[index].sended = sendedPut;
        exit();
      }
    }
  }
}

so I declare the varible

SendToHostClass sendToHost;

and instantiate sendToHost in setup() Processing method using

sendToHost = new SendToHostClass(10);
sendToHost.parameterList[0].value = 0;

As I run the code, it returns me the error message

Exception in thread “Animation Thread” java.lang.NullPointerException
at sketch_gui.setup(sketch_gui.java:273) at
processing.core.PApplet.handleDraw(PApplet.java:2117) at
processing.opengl.PGL$PGLListener.display(PGL.java:2472) at
jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:548)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:533)
at
jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:280)
at
jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:904)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:822)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:543) at
processing.opengl.PGL.requestDraw(PGL.java:814) at
processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1566)
at processing.core.PApplet.run(PApplet.java:2020) at
java.lang.Thread.run(Thread.java:662)

So what am I doing wrong?

I also discovered that if I instantiate each list object separately, it gives no error:

sendToHost = new SendToHostClass(10);
sendToHost.parameterList[0] = new ParameterClass();
sendToHost.parameterList[0].value = 0;

but it seems wrong, due to it looks that parameterList members are being instantiated twice.

Thanks in advance.

  • 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-18T16:11:47+00:00Added an answer on June 18, 2026 at 4:11 pm
    parameterList = new ParameterClass[sizeBuffer];
    

    The above statement is only creating an array, but not initializing the array elements. The array elements are initialized by their default value, which is null, in case you have the array of some custom type or some reference. So, you need to initialize the array elements separately using for loop.

    So, in your constructor you need to add a loop:

    SendToHostClass(int sizeBufferConf) {
        sizeBuffer = sizeBufferConf;
        parameterList = new ParameterClass[sizeBuffer];
    
        for (int i = 0; i < sizeBuffer; i++) {
            parameterList[i] = new ParameterList();
        }
      }
    

    But of course, first you need to make your class public, and prefer to make your fields private instead of public, and provide public accessors to make them accessible from outside.

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

Sidebar

Related Questions

I have a pretty standard class with some public member functions and private variables.
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
I'm trying to create a new object of type T via its constructor when
I am trying to create a singleton which has a non-empty constructor and to
I'm trying to create a Database object for myself in .net. The constructor takes
(Using Visual Studio 2010) I'm trying to create a shared_ptr of an existing class
I'm trying to initialize RSACryptoServiceProvider with my own public and private keys. As far
I am trying to create a simple WF4 activity that accepts a string that
I'm trying to create a class like architecture on javascript but stuck on a
public static final String PREFS_NAME = MyPrefsFile; private SharedPreferences settings; settings = getSharedPreferences(PREFS_NAME, 0);

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.