gemini88mill
gemini88mill

Reputation: 170

Similar Method call that returns lists

So i have some working code that allows me to generate a list of value to be formatted later in the program. it returns a generic List and Its leading to an API from google (QPX Express) but i don't think this matters for the question.

List<TripOption> tripOption = dataFromGoogle() //returns List

I was reading over the documentation and it seems that I can use this same API for other values in different Lists. So essentially I would like to use the same call to the API but i can only return one type of list.

dataFromGoogle(tripOption, cityData); //gives me null pointer exception

So my question would be either what would be a good way to reuse my method to grab different aspects of the API, or ELI5 what causes nullpointers because I always get them and I'm not sure I completely understand why.

Upvotes: 0

Views: 55

Answers (1)

Devin H.
Devin H.

Reputation: 1105

Null pointer exceptions are thrown when you have something like this:

Object temp = null;
temp.callMethod();

As the name suggests, the NullPointerException occurs when you have a variable that "points" at a null value and try to access something within it as if it were an object.

What's happening with yours probably has something to do with dataFromGoogle returning null, and then dataFromGoogle attempts to treat it as an object.

Upvotes: 0

Related Questions