我正在 android 上构建客户端应用程序,但在 EditText 对象中获取输入时遇到问题。我收到错误消息:空对象引用上的 android.text.Editable android.widget.EditText.getText()' package com.example.tom.friendlyhousingandroid;import android.os.Debug;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.EditText;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 java.util.HashMap;import java.util.Map;public class register extends AppCompatActivity { public EditText passwordText; public EditText emailText; public EditText firstnameText; public EditText lastnameText; public String password,email,lastname,firstname; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); passwordText = findViewById(R.id.password); emailText = findViewById(R.id.email); firstnameText = findViewById(R.id.firstnameregister); lastnameText = findViewById(R.id.lastnameregister); } public void Registration(View view){ password = passwordText.getText().toString(); email = emailText.getText().toString(); firstname = firstnameText.getText().toString(); lastname = lastnameText.getText().toString(); RequestQueue MyRequestQueue = Volley.newRequestQueue(this); String url = "http://172.16.10.92:8080/school/rest/users/addUser"; StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d("response",response); } }
2 回答
Qyouu
TA贡献1786条经验 获得超11个赞
用于电子邮件和密码的 ID 在 java 代码和 XML 中是不同的。那些一定是一样的。所以重写你的java代码来查找视图
passwordText = findViewById(R.id.passwordregister);
emailText = findViewById(R.id.emailregister);
添加回答
举报
0/150
提交
取消