java - 我该如何处理这个错误使其正确 ?"invalid method declaration; return type required"

标签 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);

        }

最佳答案

您的 Response.Listener 的右大括号 ('}') 后面缺少右括号。 (因此,末尾至少应该有两个右大括号。)

关于java - 我该如何处理这个错误使其正确 ?"invalid method declaration; return type required",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41786208/

相关文章:

android - 具有 PendingIntent 的全局广播或本地广播

java - WebView 的 postUrl 方法仅适用于显式字符串

java - 如何强制 Java 8 流按顺序执行?

java - JLabel 新行不起作用

HTML 中的 Java 无法正常工作

java - 使用JAVA程序的apk调用图

javascript - 在 Flutter 的 html 文件中使用 js 文件

android-studio - 如何运行谷歌新的 "places_compat_compatify.sh"兼容性脚本?

android-studio - 如何在 android studio 中为特定模块生成 jacoco 报告?

java - 如何计算上一个和下一个字符?