Learning how to use Retrofit in my Android App, getting following error: Please help if you can. Thank you,
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
here is my code: Please help if your able too:
public void clickButton(View view){
button = (Button) findViewById(R.id.button);
drawDate = (TextView)findViewById(R.id.drawDate);
LotteryAPI.Factory.getIstance().getLottery().enqueue(new Callback<Lottery>() {
@Override
public void onResponse(Call<Lottery> call, Response<Lottery> response) {
Log.d(TAG, "getting Draw Date");
Log.d(TAG, "Draw Date is: " + response.body().getDrawDate());
String DRAW_DATE = response.body().getDrawDate();
drawDate.setText("DRAW_DATE");
Log.d(TAG, "done setting Draw Date");
}
@Override
public void onFailure(Call<Lottery> call, Throwable t) {
Log.e("Failed", t.getMessage());
Log.d(TAG, "At onFailure - Something Failed!!");
Log.d(TAG, "error is: " + t.getCause());
}
});
}
Here is my interface:
String BASE_URL = "https://data.ny.gov/resource/h6w8-42p9.json/";
@GET("?$$app_token=xxxxxxGtxKw3s6gurSxxxxxx")
Call<Lottery> getLottery();
class Factory {
public static LotteryAPI service;
public static LotteryAPI getIstance() {
if (service == null) {
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(BASE_URL).build();
service = retrofit.create(LotteryAPI.class);
return service;
} else {
return service;
}
}
}
Here is my POJO:
@Generated("org.jsonschema2pojo")
public class Lottery {
@SerializedName("draw_date")
@Expose
private String drawDate;
@SerializedName("mega_ball")
@Expose
private String megaBall;
@SerializedName("multiplier")
@Expose
private String multiplier;
@SerializedName("winning_numbers")
@Expose
private String winningNumbers;
/**
*
* @return
* The drawDate
*/
public String getDrawDate() {
return drawDate;
}
/**
*
* @param drawDate
* The draw_date
*/
public void setDrawDate(String drawDate) {
this.drawDate = drawDate;
}
/**
*
* @return
* The megaBall
*/
public String getMegaBall() {
return megaBall;
}
/**
*
* @param megaBall
* The mega_ball
*/
public void setMegaBall(String megaBall) {
this.megaBall = megaBall;
}
/**
*
* @return
* The multiplier
*/
public String getMultiplier() {
return multiplier;
}
/**
*
* @param multiplier
* The multiplier
*/
public void setMultiplier(String multiplier) {
this.multiplier = multiplier;
}
/**
*
* @return
* The winningNumbers
*/
public String getWinningNumbers() {
return winningNumbers;
}
/**
*
* @param winningNumbers
* The winning_numbers
*/
public void setWinningNumbers(String winningNumbers) {
this.winningNumbers = winningNumbers;
}
}