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 {
@SerializedName("accountName")
public String acntName;
@SerializedName("accountNumber")
public String acntNumber;
@SerializedName("accountType")
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 {
@GET("/api/accounts.json")
public void getSamples(Callback<HashMap<String, MarkSample>> response);}
ANd lastly i'm calling my handler here UPDATED
api.getSamples(new Callback<HashMap<String, MarkSample>>() {
@Override
public void success(HashMap<String, MarkSample> stringMarkSampleHashMap, Response response) {
loading.dismiss();
int mint = stringMarkSampleHashMap.size();
Toast.makeText(mainActivity, mint, Toast.LENGTH_SHORT).show();
}
@Override
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
FATAL EXCEPTION: main
Process: com.exist.kelvs.retrofit2, PID: 2517
android.content.res.Resources$NotFoundException: String resource ID #0x3
at android.content.res.Resources.getText(Resources.java:312)
at android.widget.Toast.makeText(Toast.java:286)
at com.exist.kelvs.retrofit2.RetrofitHandler$2.success(RetrofitHandler.java:51)
at com.exist.kelvs.retrofit2.RetrofitHandler$2.success(RetrofitHandler.java:46)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)