您好,我在让 Alpha Vantage api 按我想要的方式工作时遇到问题。我只想得到最后几天的收盘价。我不确定我做错了什么。我唯一的目标是在最后几天关闭时简单地更改为 TextView“tvStockClose”。现在的错误是运行时错误。任何方向的任何帮助都将受到赞赏和欢迎。
API:链接
public void loadData() {
progressDialog.setMessage("Retrieving Data, Please Be Patient");
progressDialog.show();
Toast.makeText(getApplicationContext(), "1 :D", Toast.LENGTH_SHORT).show();
StringRequest stringRequest = new StringRequest(Request.Method.GET,
URL2,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), "2 :D", Toast.LENGTH_SHORT).show();
try {
Toast.makeText(getApplicationContext(), "3:D", Toast.LENGTH_SHORT).show();
mStockList.clear();
JSONObject jsonObject = new JSONObject(response);
String addThis = jsonObject.getJSONObject("20171102").getString("close");
tvStockClose.setText(addThis);
TestStockList testStockList = new TestStockList(addThis);
mStockList.add(testStockList);
Toast.makeText(StockTest.this, addThis, Toast.LENGTH_SHORT).show();
mAdapter = new TestMyAdapterStockList(mStockList, getApplicationContext());
recyclerView.setAdapter(mAdapter);
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "4 :D", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
//Toast.makeText(getContext(), "5 :D", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "6 :D", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Something Went Wrong, try Again", Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);
Toast.makeText(getApplicationContext(), "7 :D", Toast.LENGTH_SHORT).show();
}