There is a link to api which I broke into parts and try to get data from there - but nothing works, please tell me how to write the request correctly. Link: https://api.privatbank.ua/p24api/exchange_rates?json&date=31.08.2018
How to connect to it:
public interface IMyApi_P24 { @GET("p24api/exchange_rates") Observable<P24> getCurses(@Query("json&date") String date); } public class RetrofitClient { private static Retrofit ourInstance; public static Retrofit getInstance() { if(ourInstance == null){ ourInstance = new Retrofit.Builder() .baseUrl("https://api.privatbank.ua/") .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); } return ourInstance; } private RetrofitClient() {} } And Maine activit
public class MainActivity extends AppCompatActivity { RecyclerView rvCurs; IMyApi_P24 iMyApi_p24; CompositeDisposable compositeDisposable = new CompositeDisposable(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init(){ rvCurs = findViewById(R.id.rvContainerCurs); rvCurs.setLayoutManager(new LinearLayoutManager(this)); Retrofit retrofit = RetrofitClient.getInstance(); iMyApi_p24 = retrofit.create(IMyApi_P24.class); loadData(); } private void loadData() { Calendar calendar = Calendar.getInstance(); @SuppressLint("SimpleDateFormat") SimpleDateFormat mdformat = new SimpleDateFormat("dd.MM.yyyy"); String currDate = mdformat.format(calendar.getTime()); compositeDisposable.add(iMyApi_p24.getCurses(currDate) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<P24>() { @Override public void accept(P24 p24) throws Exception { displayData(p24); } })); } private void displayData(P24 p24) { rvCurs.setAdapter(new P24_Recycler_Adapter(p24, this)); } @Override protected void onStop() { compositeDisposable.clear(); super.onStop(); } } The application crashes, does not write a specific error in which line, Exception has just not been initialized (but I think that I rather wrote the wrong request) Thank you very much in advance!
json&dateis not a parameter name. These are two parameters:jsonanddate. - Eugene Krivenja 5:41 pm