在jsonobject之前不允许声明getParams()

时间:2016-06-10 13:50:41

标签: android android-volley

我在最后Map<String, String> getParams()之前宣布JsonObjectRequest时遇到问题。

显示错误。我正在使用此代码发布使用齐射库。当我通过Unexpected response code 500 for POST method时,答案对我没有用。

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; 
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.google.android.gms.common.api.GoogleApiClient;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;

public class LoginActivity extends AppCompatActivity {
EditText etUsername, etPassword;
Button bLogin;
String imeiNo = "123456";

private GoogleApiClient client;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_login);
    //final TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    etUsername = (EditText) findViewById(R.id.etUserName);
    etPassword = (EditText) findViewById(R.id.etPassword);
    bLogin = (Button) findViewById(R.id.bLogin);
    bLogin.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            final String userName = etUsername.getText().toString().trim();
            final String password = etPassword.getText().toString().trim();
            String tag_json_obj = "json_obj_req";
            final Map<String,String> params = null;
            final String url="/volley/resource/";
            @Override
            protected Map<String, String> getParams()throws AuthFailureError{
                Map<String, String> params = new HashMap<String, String>();
                params.put("userName", userName);
                params.put("password", password);
                params.put("imeiNo", "123456");
                return params;
            }
            final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,url,new JSONObject(params),
                    new Response.Listener<JSONObject>() {

                        @Override
                        public void onResponse(JSONObject response) {
                            VolleyLog.d(response.toString());
                            //pDialog.hide();
                        }
                    }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("Error: " + error.getMessage());
                    //pDialog.hide();
                }
            }) {
            };
            AppController.getInstance().addToRequestQueue(jsonObjReq,tag_json_obj);
            //Response.Listener<String> responseListener = new Response.Listener<String>() {
              //  @Override
               // public void onResponse(String response) {
                //    VolleyLog.v(response);
               // }
               // };
            //LoginRequest loginRequest = null;
           // loginRequest = new LoginRequest(userName, password, imeiNo, responseListener);
           // RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
            //queue.add(loginRequest);
        }
    });

}
}

0 个答案:

没有答案