2つの引数を持つAuthメソッドを持つAuthenticationクラスがあります。 そのメソッドを呼び出した後、aSyncのために、ボレーのリクエストが生成され、レスポンスが他の関数によってキャッチされます。そのオブジェクトは静的オブジェクトであり、他のクラスではアクセス可能ですが、常にオブジェクトを作成した後、またはアクティビティの初期化時にnullを示す。値オブジェクトを格納した後、1クラスから他のクラスへNull値を取得する
私の認証クラスを確認してみましょう:
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());
}
}
私は認証()メソッドことを呼び出したときに、最終的なfinalresultが値を持っていますが、私のログインクラスで、それは{}
は私のメソッド呼び出しをチェックしてみましょう示しています。
try {
Authenticate.Auth("358607051299527","1122");
} catch (TimeoutException e) {
e.printStackTrace();
}
Log.e("as","Prefrences Saved");
Log.e("as","My final result = "+Authenticate.finalresult.toString());
私はLog.e Imageを添付して理解しやすくなりました。
なぜエラーをコピーして貼り付けるのではなく、スクリーンショットを撮ったのですか? – njzk2