1
Hello, I am consuming a Json and I receive it in my fragment
, taken only 2 records and saved in a variable created at the beginning of the class, the 2 of the String type, thus:
public void onResponse(JSONObject response) {
Link link = new Link();
JSONArray json = response.optJSONArray("link");
JSONObject jsonObject = null;
try {
jsonObject = json.getJSONObject(0);
link.setTitulo(jsonObject.optString("titulo"));
link.setLink(jsonObject.optString("link"));
} catch (JSONException e) {
e.printStackTrace();
}
titulo = link.getTitulo().toString();
linkWeb = link.getLink().toString();
//Toast.makeText(getContext(), titulo + " - " + linkWeb, Toast.LENGTH_SHORT).show();
}
I tested with Toast and it’s ok, The problem is that when I use these variables outside of this method, it’s like null. which is wrong?
Vlw #Davi Ferreira, solved!
– Aristófanes Melo
opa, good! I’m glad I helped.
– dferreira