java.io.ioexception在com.android.okhttp.address @ f32949bd上意外结束流

时间:2017-12-10 03:05:10

标签: java android mysql android-studio

您好,我正在使用Mysql数据库创建一个Android应用程序,我正在尝试进行用户注册!任何人都可以帮助我PLZ

   

当我点击注册按钮时收到此错误:java.io.ioexception意外结束了com.android.okhttp.address @ f32949bd

这是我的代码:

package androidloginandregistration.inducesmile.com.enpascheres;

/**
 * Created by User on 10/12/2017.
*/

public class Constants {
    public static final  String ROOT_URL ="http://192.168.1.3/android/v1/registerUser.php";

public static final String  URL_REGISTER = ROOT_URL+"registerUser.php";
}

这是主要的活动:

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private EditText editTextUsername,editTextEmail,editTextPassword;
private Button buttonRegister;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editTextEmail=(EditText)findViewById(R.id.editTextEmail);
    editTextUsername=(EditText)findViewById(R.id.editTextUsername);
    editTextPassword=(EditText)findViewById(R.id.editTextPassword);

    buttonRegister=(Button)findViewById(R.id.buttonRegister);

    progressDialog = new ProgressDialog(this);

    buttonRegister.setOnClickListener(this);
}

private void registerUser(){
    final String email= editTextEmail.getText().toString().trim();
    final String username= editTextUsername.getText().toString().trim();
    final String password= editTextPassword.getText().toString().trim();

    progressDialog.setMessage("Registering user ...");
    progressDialog.show();
    StringRequest stringRequest = new StringRequest(Request.Method.POST,

            Constants.URL_REGISTER,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    try {
                        JSONObject jsonObject= new JSONObject(response);

                        Toast.makeText(getApplicationContext(),jsonObject.getString("message"),Toast.LENGTH_LONG).show();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            progressDialog.hide();
            Toast.makeText(getApplicationContext(),error.getMessage(),Toast.LENGTH_LONG).show();

        }
    }){


        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String> params = new HashMap<>();
            params.put("username",username);
            params.put("email",email);
            params.put("password",password);
            return params;
        }
    };

    RequestQueue requestQueue= Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);


}

@Override
public void onClick(View view) {
    if(view==buttonRegister)
        registerUser();

}

}

0 个答案:

没有答案