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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:57:49+00:00 2026-06-17T15:57:49+00:00

I have created a datatype with two fields, time and measurement. I create an

  • 0

I have created a datatype with two fields, time and measurement. I create an array of these datatypes. When i then attempt to assign a value to one of the fields of array[0] I get a null pointer exception. can anyone tell me what is wrong?

Public class MeasurementPoint{

private int time;
private double  measurement;

public MeasurementPoint(){
this.time =0;
this.measurement =0;}}

public void setMeausurement(double value){
this.measurement = value;}
public double getMeasurement (){
return this.measurement;}

public void setTime(int value){
this.time = value;}
public int getMeasurement (){
return this.time;}
}

The code that I use to create the Array is below

MeasurementPoint [] controlValues = new MeasurementPoint [points];
System.out.println(controlValues.length(); // this gives me 16 so I know the array is created

controlValues[0].setMeasurement(aCtivity);// this is where I get the exception.
  • 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-17T15:57:50+00:00Added an answer on June 17, 2026 at 3:57 pm

    You initialized your array but you never initialized your Array Elements, thus you get NullPointerException when you try to acess the zero’th index of your array as yourarray[0] returns null and you try to call setMe…() on null.. you have to actually initialize your array elements.

    MeasurementPoint [] controlValues = new MeasurementPoint [points];
    controlValues[0] = new Measurementpoint(val1,val2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In c++, I am attempting to create an array to store two different datatypes.
I have two tables auth_user and temp These are their schema: CREATE TABLE auth_user
I have a SQL Server table which has 625 columns created with different datatypes
I have two entities, Customer and Order, both of which I have created types
I have created a javascript object var spanglist = { one: q1, two:q2, three:q3,
I have created an inherited class StorageMedium from a base I called DataTypes. StorageMedium
I have a report in ssrs 2008 r2.I have created two multi-valued parameter on
The task: I am trying to create a custom data type and have it
I have created a QWidget with a bunch of QToolButtons in it and I
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -

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.