android studio com.android.volley.NoConnectionError:本地主机的java.io.EOFException

时间:2018-11-04 05:30:01

标签: java android android-studio xampp

我在这里有一个非常基本的注册应用程序的脚本。它似乎没有连接到XAMPP localhost php文件夹。它将引发此“ com.android.volley.NoConnectionError:java.io.EOFException。”

我不知道我是否弄错了XAMPP设置,但是我进行了很多调试,并将其作为我的错误。

这是RegisterRequest脚本;

public class RegisterRequest extends JsonObjectRequest {

    private static final String REGISTER_REQUEST_URL = "http://192.168.*.*:3306/testing/Register.php";
    private Map<String, String> params;
    public RegisterRequest(String username, String password,String isAdmin,
                           Response.Listener<JSONObject> listener,
                           Response.ErrorListener errListener){
        super(Method.POST, REGISTER_REQUEST_URL, new JSONObject(), listener, errListener);
        params = new HashMap<>();
        params.put("username",username);
        params.put("password",password);
        params.put("isAdmin",isAdmin+"");
    }

    public Map<String, String> getparams() {
        return params;
    }
}

这是createuser脚本,如果需要的话;

public class CreateUser extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_user);
        this.setTitle("Create User");
        final EditText username1 = findViewById(R.id.Createusername);
        final EditText password1 = findViewById(R.id.CreatePassword);
        final Switch isAdmin = findViewById(R.id.isadmin);
        final Button createuser = findViewById(R.id.createuserbtn);
        if (getIntent().hasExtra("com.example.northlandcaps.crisis_response")){
            isAdmin.setVisibility(View.GONE);
        }
        createuser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final String username = username1.getText().toString();
                final String password = password1.getText().toString();
                final String isadmin = isAdmin.getText().toString();
                Response.Listener<JSONObject> responseListener = new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            boolean success = response.getBoolean("success");
                            if (success){
                                Intent intent = new Intent(CreateUser.this, MainActivity.class);
                                startActivity(intent);
                            }else{
                                AlertDialog.Builder builder = new AlertDialog.Builder(CreateUser.this);
                                builder.setMessage("Register Failed")
                                        .setNegativeButton("Retry",null)
                                        .create()
                                        .show();


                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                };
                RegisterRequest registerRequest = new RegisterRequest(username,password,isadmin,responseListener,errorListener);
                int socketTimeout = 250000;//30 seconds - change to what you want
                RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
                registerRequest.setRetryPolicy(policy);
                // Creating RequestQueue.
                RequestQueue queue = Volley.newRequestQueue(CreateUser.this);

                // Adding the StringRequest object into requestQueue.
                queue.add(registerRequest);
            }
        });
    }
    Response.ErrorListener errorListener = new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(), String.valueOf(error), Toast.LENGTH_SHORT).show();
            Log.e("Create User", error+"");
            error.printStackTrace();
        }
    };

是否可能我输入的URL错误?我在清单中打开了互联网特权。是我的XAMPP设置吗?我似乎无法得到解决此问题的可靠答案。预先感谢。

0 个答案:

没有答案