0

people so I have a valid URL with JSON data in it, I pull the data with volley but it's not working for some reason, when I change the URL it works. But I need to use this URL with this data in my project. I think the structure of the URL is the problem, but I don't know how to fix it, Please help. Thank you!

The URL I am using is https://zlatnakopacka.mk/api/TopOfferPreview_feed?source=zk


public class TestOne extends AppCompatActivity {


    String url = "https://zlatnakopacka.mk/api/TopOfferPreview_feed?source=zk";
    RecyclerView recyclerView;
    PonudiAdapter adaptor;
    ArrayList<Ponudi> ponudis;
  



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_one);

   switchSve = findViewById(R.id.switch1);
        recyclerView = findViewById(R.id.testRecycler);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adaptor = new PonudiAdapter(getApplicationContext());
        recyclerView.setAdapter(adaptor);
        ponudis = new ArrayList<>();

        getData("1");

        switchSve.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked == true) {
                    getData("sve");
                } else {
                    getData("1");
                }

            }
        });



private void getData(final String Sport) {

     //   final ProgressDialog progressDialog = new ProgressDialog(this);
     //   progressDialog.setMessage("Се вчитува...");
      //  progressDialog.show();

        ponudis.clear();

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {

                try {
                    for (int i = 0; i < response.length(); i++) {
                        JSONObject jsonObject = response.getJSONObject(i);
                        Ponudi ponudi = new Ponudi();
                        ponudi.setSh_sport_id(jsonObject.getString("sh_sport_id"));
                        ponudi.setTim1(jsonObject.getString("tim1"));
                        ponudi.setTim2(jsonObject.getString("tim2"));
                        ponudi.setLiga_header(jsonObject.getString("liga_header"));
                        ponudi.setDatum_vreme(jsonObject.getString("datum_vreme"));
                        ponudi.setKh1(jsonObject.getString("kh1"));
                        ponudi.setKhx(jsonObject.getString("khx"));
                        ponudi.setKh2(jsonObject.getString("kh2"));
                        ponudi.setKod(jsonObject.getString("broj"));

                        if (ponudi.getSh_sport_id().equals(Sport)) {
                            ponudis.add(ponudi);
                        } if (Sport.equals("sve")) {
                            ponudis.add(ponudi);
                        }


                    }
                } catch (JSONException e) {
                    Toast.makeText(TestOne.this, "Json is not valid", Toast.LENGTH_SHORT).show();

                }

                adaptor.setData(ponudis);
                adaptor.notifyDataSetChanged();
              //  progressDialog.dismiss();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
              //  progressDialog.dismiss();
                Toast.makeText(TestOne.this, "Error", Toast.LENGTH_SHORT).show();
            }
        });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(jsonArrayRequest);


      }

    }

2 Answers2

0

In response you are getting below error.

"javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

I found some answers here is reference that will help you.

Trusting all certificates using HttpClient over HTTPS

Rinki Devi
  • 71
  • 4
0

Replace getData() Method

Write This method -

private void getData() {

     //   final ProgressDialog progressDialog = new ProgressDialog(this);
     //   progressDialog.setMessage("Се вчитува...");
      //  progressDialog.show();

        ponudis.clear();

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {

                try {
                    for (int i = 0; i < response.length(); i++) {
                        JSONObject jsonObject = response.getJSONObject(i);
                        Ponudi ponudi = new Ponudi();
                        ponudi.setSh_sport_id(jsonObject.getString("sh_sport_id"));
                        ponudi.setTim1(jsonObject.getString("tim1"));
                        ponudi.setTim2(jsonObject.getString("tim2"));
                        ponudi.setLiga_header(jsonObject.getString("liga_header"));
                        ponudi.setDatum_vreme(jsonObject.getString("datum_vreme"));
                        ponudi.setKh1(jsonObject.getString("kh1"));
                        ponudi.setKhx(jsonObject.getString("khx"));
                        ponudi.setKh2(jsonObject.getString("kh2"));
                        ponudi.setKod(jsonObject.getString("broj"));

                        if (ponudi.getSh_sport_id().equals("1")) {
                            ponudis.add(ponudi);
                        } else if(ponudi.getSh_sport_id().equals("sve")) {
                            ponudis.add(ponudi);
                        }


                    }
                } catch (JSONException e) {
                    Toast.makeText(TestOne.this, "Json is not valid", Toast.LENGTH_SHORT).show();

                }

                adaptor.setData(ponudis);
                adaptor.notifyDataSetChanged();
              //  progressDialog.dismiss();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
              //  progressDialog.dismiss();
                Toast.makeText(TestOne.this, "Error", Toast.LENGTH_SHORT).show();
            }
        });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(jsonArrayRequest);


      }