user3262438 user3262438 - 1 year ago 158
Android Question

Retrofit HashMap is null

Hi i'm trying to learn android and currently implementing retrofit and tried to solve this using related post here sadly nothing Helped me pls hear me out.

I have a json data that i need to parse here it is

"-KNea90tV5nZlkeqxc3Q": {
"accountName": "Mark Angelo Noquera",
"accountNumber": "12435656443",
"accountType": "Peso Savings"
"-KNeaPmBoTXV4mQC6cia": {
"accountName": "Mark Angelo Noquera",
"accountNumber": "12435656444",
"accountType": "Peso Checking"
"-KNeaWe_ZbtI9Tn6l-oF": {
"accountName": "Mark Angelo Noquera",
"accountNumber": "12435656445",
"accountType": "Personal Loan"

Then some tutorials told me to use a hashmap so i implemented mine
here is my ModelClass1.class

public class MarkSamples {
public HashMap<String, MarkSample> marksamples;
public HashMap<String, MarkSample> getMarksamples() {
return marksamples;

ModeClass2.class - For handling the objects

public class MarkSample {

public String acntName;
public String acntNumber;
public String acntType;

public String getName() {
return (acntName);

public void setName(String acntName) {
this.acntName = acntName;

public String getNumber() {
return (acntNumber);

public void setNumber(String acntNumber) {
this.acntNumber = acntNumber;

public String getType() {
return (acntType);

public void setType(String acntType) {
this.acntType = acntType;


My API is here UPDATED

public interface ContactsAPI {
public void getSamples(Callback<HashMap<String, MarkSample>> response);}

ANd lastly i'm calling my handler here UPDATED

api.getSamples(new Callback<HashMap<String, MarkSample>>() {
public void success(HashMap<String, MarkSample> stringMarkSampleHashMap, Response response) {
int mint = stringMarkSampleHashMap.size();
Toast.makeText(mainActivity, mint, Toast.LENGTH_SHORT).show();

public void failure(RetrofitError error) {


And everytime i TOast the outcome i got a null value did i implemented it wrong? Im certain i used my RootUrl correctly if this is not the problem what are the other methods i can use? please help me.

here is my Logcat UPDATED

Process: com.exist.kelvs.retrofit2, PID: 2517
android.content.res.Resources$NotFoundException: String resource ID #0x3
at android.content.res.Resources.getText(
at android.widget.Toast.makeText(
at com.exist.kelvs.retrofit2.RetrofitHandler$2.success(
at com.exist.kelvs.retrofit2.RetrofitHandler$2.success(
at retrofit.CallbackRunnable$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)

Answer Source

Update api definition to:

public void getSamples(Map<String,MarkSample> response);}

And api call to:

api.getSamples(new Callback<Map<String,MarkSample>() {
        public void success(Map<String,MarkSample> samplelist, Response response) {
            int mint = samplelist.size();


To get all accountNames add this code to your callback:


int mint = 0;
if (samplelist!=null){  
  mint = samplelist.size(); 
  for (MarkSample item:samplelist.values()){
    Log.d("TEST","value: "+item.getName(); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download