I am new to android programming and I am trying to connect to server with retrofit and get some data. I made a little example just to check if it would return some data. First there is a problem that I don't know if I even wrote the code to do what I want and second I get the errors:
"Error:(64, 52) error: is not abstract and does not override abstract method failure(RetrofitError) in Callback" and 2 errors " Error:(67, 13) error: method does not override or implement a method from a supertype"
Here is my code
public class MainActivity extends ListActivity{
public static final String ENDPOINT = "http://tinoba.hostzi.com";
List<Jelovnik> jelovnik;
Button gumb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gumb = (Button)findViewById(R.id.gumb);
}
public void stisni(View view) {
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(ENDPOINT)
.build();
JelovnikAPI api = adapter.create(JelovnikAPI.class);
api.getFeed(new Callback<List<Jelovnik>>() {
@Override
public void onResponse(Response<List<Jelovnik>> response, Retrofit retrofit) {
jelovnik = response.body();
gumb.setText(jelovnik.get(0).getIme().toString());
}
@Override
public void onFailure(Throwable throwable) {
}
});
}
} and my retrofit interface
public interface JelovnikAPI {
@GET("/read.php")
public void getFeed(Callback<List<Jelovnik>> response);
}
The version of Callback
you are using is from Retrofit 2
and you are still using Retrofit 1.x
. Callback has two methods, failure
and success
. Your callback should look like
new Callback<List<Jelovnik>>() {
@Override
success(List<Jelovnik> t, Response response) {
}
@Override
public void failure(RetrofitError error) {
}
});
Replace Throwable
with RetrofitError
:
@Override
public void onFailure(RetrofitError retrofitError) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.