如何处理此错误使其正确?“无效的方法声明;需要返回类型”

时间:2017-01-22 00:51:24

标签: java android android-studio

我如何修复此错误,其中我收到“无效的方法声明;需要返回类型”和错误“缺少方法体或声明抽象”

请帮忙。我很感激善良。

private void login(final String email, final String password) {
        //Tag used to cancel the request
        String tag_string_req = "req_login";
        progressDialog.setMessage("Logging in....");
        progressDialog.show();

        StringRequest strReq = new StringRequest(Request.Method.POST,
                Utils.LOGIN_URL, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d(TAG, "Login Response: " + response.toString());

                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");

                    //check for error node in json
                    if (!error) {
                        //now store the user in SQLite
                        JSONObject user = jObj.getJSONObject("user");
                        String uName = user.getString("username");
                        String email = user.getString("email");

                        //Inserting row in users table
                        userInfo.setEmail(email);
                        userInfo.setUsername(uName);
                        session.setLoggedin(true);

                        startActivity(new Intent(Login.this, MainActivity.class));
                        finish();
                    } else {
                        //error in login, get the error message
                        String errorMsg = jObj.getString("error_msg");
                        toast(errorMsg);
                    }
                } catch (JSONException e) {
                    //json error
                    e.printStackTrace();
                    toast("Json error: " + e.getMessage());

                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Login Error: " + error.getMessage());
                toast("Unknown Error occured");
                progressDialog.hide();
            }

        }) {
            @Override
            protected Map<String, String> getParams() {
                //Posting parameters to login url
                Map<String, String> params = new HashMap<>();
                params.put("email", email);
                params.put("password", password);

                return params;

            }

这是我收到错误的地方:

    //Adding request to request queue
                AndroidLoginController.getInstance().addToRequestQueue(strReq, tag_string_req);

        }

1 个答案:

答案 0 :(得分:1)

您在Response.Listener的结束大括号('}')之后缺少右括号。 (所以,最后应该至少有两个结束的花括号。)