我的问题是,当我在真正的移动设备上运行我的应用程序时,会显示以下错误:com.android.volley.TimeoutError”。但是,通过使用Android工作室的模拟器,它可以完美地工作。由于此错误必须由连接问题引起,因此我是否为我的应用程序使用相应的ip?即
“私有静态字符串 URL_REGIST =”http://10.0.2.2:81/android_register_login/register.php“;"
我是应用程序开发的新手,因此非常感谢任何帮助。以下是用于注册的代码.java它使用register.php用于执行注册的脚本
private EditText name,email,password,c_password;
private Button btn_regist;
private ProgressBar loading;
private static String URL_REGIST ="http://10.0.2.2:81/android_register_login/register.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
loading = findViewById(R.id.loading);
name= findViewById(R.id.name);
email = findViewById(R.id.email);
password = findViewById(R.id.password);
c_password = findViewById(R.id.c_password);
btn_regist =findViewById(R.id.btn_regist);
btn_regist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Regist();
}
});
}
private void Regist(){
loading.setVisibility(View.VISIBLE);
btn_regist.setVisibility(View.GONE);
final String name = this.name.getText().toString().trim();
final String email = this.email.getText().toString().trim();
final String password = this.password.getText().toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
if(success.equals("1")){
Toast.makeText(RegisterActivity.this, "Account Created",Toast.LENGTH_SHORT).show();
loading.setVisibility(View.GONE);
}
}
一只萌萌小番薯
白猪掌柜的
互换的青春
相关分类