简体   繁体   English

Android Studio说volley.NoConnectionError:java.io.EOFException,这是什么?

[英]Android studio says volley.NoConnectionError: java.io.EOFException, what is this?

I have a super basic register script in android studio. 我在android studio中有一个超级基本的注册脚本。 Im trying to get it to connect to a php file located in the Localhost of XAMMP. 我试图让它连接到XAMMP的Localhost中的php文件。 My question is unique because i directing my script to a specific localhost url, not searching on the internet. 我的问题很独特,因为我将脚本定向到特定的本地主机URL,而不是在Internet上搜索。 The URL is accurate too, unless it has to be changed BACK to being localhost(not ip). 该URL也是准确的,除非必须将其更改回localhost(不是ip)。 The error code is 错误代码是

E/Create User: com.android.volley.NoConnectionError: java.io.EOFException E /创建用户:com.android.volley.NoConnectionError:java.io.EOFException

here is the register request; 这是注册请求;

public class RegisterRequest extends StringRequest {

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

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

here is the CreateUser class; 这是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<String> responseListener = new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonResponse = new JSONObject(response);
                            boolean success = jsonResponse.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);
                RequestQueue queue = Volley.newRequestQueue(CreateUser.this);
                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+"");
        }
    };

The php file, like i said, is inside htdocs inside of XAMMP. 就像我说的那样,PHP文件位于XAMMP的htdocs内。 both apache and mysql are running, however, someone said i may not have my php script invoked by apache. apache和mysql都在运行,但是,有人说我可能没有apache调用我的php脚本。 Or that php even enabled on my Apache server. 甚至在我的Apache服务器上启用了该php。

try this 尝试这个

int socketTimeout = 500000;//30 seconds - change to what you want
            RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
            stringRequest.setRetryPolicy(policy);
            // Creating RequestQueue.
            RequestQueue queue = Volley.newRequestQueue(CreateUser.this);

            // Adding the StringRequest object into requestQueue.
            queue.add(registerRequest);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM