welcome_java
welcome_java

Reputation: 3

Getting Null Pointer exception when trying to get value from hashmap object in java?

I have one field in my DTO named Details class something like this

class Datas{
    private Details details;
}

In Details class I have field something like this

class Details{
private HashMap<String, Data> data;
}

in Data class I have variables like

private String name;
private String id;

Now when I am trying to get and set the value something like this

 information.setDescription(
                        item.get(i).getDatas().Details().get("data").getName());

I am getting null pointer exception ,

sample Json Object

 "data" : {
               "12345" : {
               "name" : "bhushan",
                "id" : "1"
    }

error:- java.lang.NullPointerException: null

Upvotes: 0

Views: 325

Answers (1)

AaqilSh
AaqilSh

Reputation: 159

information.setDescription(
                    item.get(i).getDatas().Details().get("data").getName());

Case sensitive matters!

Upvotes: 1

Related Questions