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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:14:51+00:00 2026-06-07T01:14:51+00:00

This is the first version of my code : public class ListSchedule implements ListInterface

  • 0

This is the first version of my code :

public class ListSchedule implements ListInterface {

    private ArrayList<Schedule> list;

    private String cookie;

    public ListSchedule() {
        this.list = new ArrayList<Schedule>();
    }

    public ArrayList<Schedule> getList() {
        return list;
    }
}

In another class, I made this call :

protected final ListSchedule parse(String jsonString)
        throws CustomException {

    ListSchedule list = new ListSchedule();

    JSONArray schedulesArray;

    try {

        // Convert the response to a JSONObject
        JSONObject json = new JSONObject(jsonString);

        try {

            int errorCode = json.getInt("error");

            // Check if there is no error from FilBleu server
            if (errorCode > 0) {
                throw new CustomException(
                        CustomException.ERROR_FILBLEU,
                        "DataAccessObject", "Server error "
                                + json.getInt("subError"));
            }

            try {
                String cookie = json.getString("cookie");
                list = new ListSchedule(cookie);
            } catch (JSONException e) {
                throw new CustomException(CustomException.JSON_FORMAT,
                        "DataAccessObject", "No cookie value");
            }

            schedulesArray = json.getJSONArray("schedules");

            // NullPointerException with the line below
            Log.d("DAO", list.getList().toString());

            parseSchedulesArray(list, schedulesArray);

        } catch (JSONException e) { // Unable to get the error code
            throw new CustomException(CustomException.JSON_FORMAT,
                    "DataAccessObject", "Bad JSON format ("
                            + e.getMessage() + ")");
        }

    } catch (JSONException e) { // Unable to convert response
        throw new CustomException(CustomException.JSON_FORMAT,
                "DataAccessObject", "Bad JSON format ("
                        + e.getMessage() + ")");
    }

    return list;
}

then I had a NullPointerException from the line Log.d("DAO", list.getList().toString());. So I tried another solution. As you can see, the only difference is the initialization of the list property :

public class ListSchedule implements ListInterface {

    private ArrayList<Schedule> list = new ArrayList<Schedule>();

    private String cookie;

    public ListSchedule() {
    }

    public ArrayList<Schedule> getList() {
        return list;
    }
}

and the NullPointerException was never thrown again…

I don’t really understand the difference between the two ways of initializing the list property. Can somebody give me a hint please ?

  • 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-07T01:14:52+00:00Added an answer on June 7, 2026 at 1:14 am

    I am speculating that the following constructor exists in your code base :

    public ListSchedule(String cookie) {
            this.cookie = cookie;
        }
    

    and what you need is the following:

         public ListSchedule(String cookie) {
                    this.cookie = cookie;
                    this.list = new ArrayList<Schedule>();
                }
    

    This is further validated by the invocation of this line in your program:

    list = new ListSchedule(cookie);
    

    Notice how you don’t initialize the list in the second constructor. Also you start by invoking the default constructor, but you later reassign the pointer to the object into what gets created from the String constructor of ListSchedule.

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

Sidebar

Related Questions

Is this valid C# code ? public class Product { [CompilerGenerated] private string <Name>k__BackingField;
I have like 400 records on my database, suppose this is the first version
Currently using MySQL version 5.1.6 This is my first real world build and so
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a
Code first: '''this is main structure of my program''' from twisted.web import http from
I have a Java class that looks like this: public class My_ABC { int
I have two versions of code. In the first version type of exception which
I found this code on the website http://rosettacode.org/wiki/Closest-pair_problem and I adopted the C# version
I have here this code. I want it to first display an image file

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.