Android登录模块失效求助:点击登录按钮无响应
Let's walk through the most likely causes for your login button doing nothing when clicked, even though your registration flow works perfectly. We’ll start with quick checks and move to targeted fixes.
1. Add Volley Error Listener to Catch Hidden Failures
Right now, your LoginRequest ignores network errors entirely—if the request fails (e.g., no internet, broken PHP script, incorrect URL), you’ll never get feedback. This is almost certainly why you’re seeing no response when clicking the button.
Fix: Update LoginRequest and Add Error Handling
First, modify your LoginRequest constructor to accept an error listener:
public LoginRequest(String username, String password, Response.Listener<String> listener, Response.ErrorListener errorListener) { super(Request.Method.POST, LOGIN_REQUEST_URL, listener, errorListener); params = new HashMap<>(); params.put("username", username); params.put("password", password); }
Then, add the error handler to your LoginActivity’s login button click logic to see exactly what’s failing:
blogin.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ final String username=etusername.getText().toString(); final String password=etpassword.getText().toString(); Response.Listener<String> responseListener= new Response.Listener<String>(){ // Keep your existing onResponse code here }; // Add this error listener to debug failures Response.ErrorListener errorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { android.util.Log.e("LOGIN_ERROR", "Request failed: " + error.getMessage(), error); AlertDialog.Builder builder= new AlertDialog.Builder(LoginActivity.this); builder.setMessage("Login failed: Check your internet connection or try again later") .setNegativeButton("Retry", null) .create().show(); } }; LoginRequest loginRequest=new LoginRequest(username,password,responseListener, errorListener ); RequestQueue queue= Volley.newRequestQueue(LoginActivity.this); queue.add(loginRequest); } });
This will immediately show you if the problem is network-related.
2. Double-Check Button ID in Your Layout
Make sure the button in activity_login.xml has the exact ID blogin that you’re referencing in code. If the ID doesn’t match, the click listener never attaches, so clicking the button does nothing.
Verify your layout has this:
<Button android:id="@+id/blogin" <!-- Rest of your button attributes --> />
3. Fix Potential Issues in Your PHP Script
Your AbloLogin.php has a couple of small issues that could cause unexpected behavior:
- Unnecessary while loop: Since username/password combinations should be unique, you only need to check for one matching row. Using
whiledoesn’t break things, butifis more logical here. - Missing error reporting: If your PHP script has bugs (e.g., wrong database credentials, typos in table/column names), you’ll never see them unless you enable error output.
Updated PHP Script:
<?php // Enable error reporting for debugging (remove in production) error_reporting(E_ALL); ini_set('display_errors', 1); $con = mysqli_connect("localhost", "id4335430_ablo_users", "wontreveal", "id4335430_ablo_users"); // Check if database connection failed if (!$con) { $response["success"] = false; $response["error"] = "Database connection failed: " . mysqli_connect_error(); echo json_encode($response); exit; } $username = $_POST["username"]; $password = $_POST["password"]; $statement = mysqli_prepare($con, "SELECT * FROM allusers WHERE username = ? AND password = ?"); mysqli_stmt_bind_param($statement, "ss", $username, $password); mysqli_stmt_execute($statement); mysqli_stmt_store_result($statement); mysqli_stmt_bind_result($statement, $allusersID, $name, $username, $password); $response = array(); $response["success"] = false; // Use if instead of while for unique login credentials if(mysqli_stmt_fetch($statement)){ $response["success"] = true; $response["name"] = $name; $response["username"] = $username; } echo json_encode($response); // Clean up resources mysqli_stmt_close($statement); mysqli_close($con); ?>
This adds connection error checking and makes the login logic clearer.
4. Confirm Internet Permission in AndroidManifest
Make sure your AndroidManifest.xml includes the internet permission—without this, Volley can’t send network requests at all:
<uses-permission android:name="android.permission.INTERNET" />
Place this right above the <application> tag.
Next Steps
- Add the error listener first—it will tell you immediately if the problem is network-related.
- Verify your button ID and internet permission are correct.
- Test the PHP script directly (e.g., use a tool like Postman to send a POST request with username/password parameters) to confirm it returns the correct JSON response.
内容的提问来源于stack exchange,提问作者M.S.Sudha

