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

  • Home
  • SEARCH
  • 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 8264225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:22:45+00:00 2026-06-08T04:22:45+00:00

I have a simple dataset class similar to: class DataSet { private String value;

  • 0

I have a simple dataset class similar to:

class DataSet {
    private String value;
    private String additionalValue;

    public DataSet(String value, String additionalValue) {
        this.value = value;
        this.additionalValue = additionalValue;
    }

    public String getAdditionalValue() {
        return this.additionalValue;
    }
}

Then I have created an ArrayList<DataSet> and added a new element DataSet("Value1", null).

Now at some point I need to check if the entry with value "Value1" has additionalValue and if it does, what it is.

I do a simple loop checking if value.equals("Value1") == true, then I do:

if (element.getAdditionalValue() != null) {
    return element.getAdditionalValue();
}

However, as soon as it gets to the if statement, it throws an error saying that the value is null.
How can I make it so that it doesn’t throw an error and just skips the return statement if additionalValue is null?

EDIT:

But the thing is that the element cannot be null at the point where it checks additionalValue as it passed through the element.getValue.equals("Value1") condition.

for (DataSet element : dataSet) {
    if (element.getValue.equals("Value1")) {
        if (element.getAdditionalValue() != null) {
            return element.getAdditionalValue();
        }
     }
}
  • 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-08T04:22:47+00:00Added an answer on June 8, 2026 at 4:22 am

    I think the problem is that your element object is null, so you have to check it before checking additionalValue.

    if (element != null && element.getAdditionalValue() != null){
       return element.getAdditionalValue();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple hirachey of Tasks similar to the snipet below: public class
I have a simple function GetPageName(String PageFileName, String LangCode) defined inside a class file.
I have a simple select from a typed dataset: var productlist = from prds
I have fit a simple bi-variate VAR model to this data set and I
I have simple class with width and height member fields which define number of
I have code that calls the ReadXml method of the DataSet class and passes
I have a simple application that retrieves a dataset from the database and converts
I have data-set represented as latitude-longitude and a VALUE(named class) associated with each latitude-longitude
I have written a simple RPC class that lets me serialize and send binary
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which

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.