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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:14:18+00:00 2026-05-26T14:14:18+00:00

This is my for loop function inside the servlet Here i have a question

  • 0

This is my for loop function inside the servlet

Here i have a question .
The Data will be passed from the USER Interface to this .

In some conditions , some information (For example symbol or side ) may not be passed , then in those conditions , i am getting NullPointreException as null would be supplied to it .

List<Bag> bags = new ArrayList<Bag>(bagdata.length);

for (FormBeanData ld : data) {
    Bag bag = new Bag();
    bag.symbol = ld.getSymbol();
    bag.side = ld.getSide();
    bags.add(bag );
}

Is there anyway we can handle such situations ??

Thank you .

  • 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-05-26T14:14:18+00:00Added an answer on May 26, 2026 at 2:14 pm

    The code you submitted most likely does not even compile: bags.add(Bag) does not make sense. You need to add the bag object (the instance), not Bag (the class).

    In any case if you want to check if a reference is null just check it:

    if (myobject != null) {
        myobject.myfield = ... // myobject is not null
    } else {
        // ignore, print an error, do what is required to do
    }
    

    You also have to check before iterating

    if (collection != null) {
      for (Object o : collection) {
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this recursion loop where inside the function I have atleast 2 ajax
I need to create a function that uses a loop. This function will open
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
Here's some JavaScript: linkElem.click(function () { var data = linkElem.data(); alert(''+data.mls + ' '
I have a $.post function inside of a loop. All it does it call
Here is my code. My question has to do with the append function inside
Quick question - I've got a $.each loop, with a function call inside with
I wrote this function for filling closed loop, pixvali is declared globally to store
This js loop script always get the last value of ui_item inside a jquery
I have some code here : http://bitbucket.org/natim/lo53_tp1/src/tip/part3/camions/medias/js/tracking.js That I use to draw some information

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.