Reputation: 83
this is my class where retrofit is called.
public class Prelist_fragment extends ListActivity {
String API = "http://nisani.net/nisani hoarding/";
String tag;
Datum datum;
private ArrayList<String> stores = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(tag, "in oncreate of prelist");
retro();
}
void retro(){
Log.e(tag, "inside retro");
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(API).build(); //create an adapter for retrofit with base url
gitapi git = restAdapter.create(gitapi.class);
git.getStores("hij",new Callback<PreStoreResponse>() {
@Override
public void success(PreStoreResponse preStoreResponse, Response response) {
stores.add(datum.getStore());
TextView tView = new TextView(Prelist_fragment.this);
getListView().addHeaderView(tView);
setListAdapter(new ArrayAdapter<String>(Prelist_fragment.this,
R.layout.activity_prelist_fragment,stores));
getListView().setTextFilterEnabled(true);
}
@Override
public void failure(RetrofitError error) {
Log.e(tag, "inside retro error"+error.getUrl()+" "+error.getMessage());
if (error.isNetworkError()) {
Log.e(tag,"network error"); // Use another code if you'd prefer
}
}
});
}
and this is my interface.
public interface gitapi {
/* GET LIST*/
@GET("/pre_report.php") //a function in your api to get all the list
public void getStores(@Query("roll")String a,Callback<PreStoreResponse> response);
}
when i tried this, it is showing 404 not found. the url is correct, i checked that. the response is going on onfailure of retrofit not on onsuccess.
Upvotes: 0
Views: 8626
Reputation: 7918
My first guess would be that Retrofit is failing because of the space in your endpoint URL.
When typing it into a browser, the browser automatically converts that space into '%20', which it then understands. I'm not sure that Retrofit is able to do the same. Retrofit might simply be removing that space, converting your original URL into "http://nisani.net/nisanihoarding/", which obviously gives a 404 error.
Try and change your endpoint URL to:
http://nisani.net/nisani%20hoarding/
Upvotes: 4