【发布时间】:2016-10-06 14:10:12
【问题描述】:
我有 Authentication 类,它有 Auth 方法和 2 个参数。 在调用该方法后,由于 aSync,生成了一个凌空请求并通过其他函数捕获响应。该对象是一个静态对象,可以在其他类中访问,但在创建对象或在活动的创建上初始化它之后总是显示 null。
让我们检查一下我的 Authenticate 类:
public class Authenticate {
private static final String URL = "http://allskkc/zaigham/idsrs_authentication.php";
public static JSONObject finalresult;
public Authenticate() {
}
public static void Auth(String IEMI, String PIN) throws TimeoutException {
final JSONObject params = new JSONObject();
finalresult = new JSONObject();
RequestQueue queue = Volley.newRequestQueue(Splash.context);
try {
params.put("iemi", IEMI);
params.put("pin", PIN);
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("params to server", params.toString());
JsonObjectRequest jsOBJRequest = new JsonObjectRequest
(Request.Method.POST, URL, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("response from server", response.toString());
ftn(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Response error",error.toString());
}
});
queue.add(jsOBJRequest);
}
public static void ftn(JSONObject jsonObject) {
finalresult = jsonObject;
Log.e("as", "Response in ftn() = " + finalresult.toString());
}
}
final finalresult 在我调用 Auth() 方法时具有价值,但在我的 Login 类中它显示 {}
让我们检查一下我的方法调用:
try {
Authenticate.Auth("358607051299527","1122");
} catch (TimeoutException e) {
e.printStackTrace();
}
Log.e("as","Prefrences Saved");
Log.e("as","My final result = "+Authenticate.finalresult.toString());
【问题讨论】:
-
为什么你把错误截图而不是复制粘贴?
标签: android json android-studio android-volley