尝试对空对象引用调用虚拟方法“android.text.editable android.widget.edittext.gettext()”。我试过所有可能的案子,但没有解决,需要建议。有人能帮我解决这个问题吗?我对insert方法使用restapi。xml文件上的文本数相同。
public class LoginActivity extends AppCompatActivity {
EditText edt_first,
edt_mid,
edt_fam,
edt_egn,
edt_phone,
edt_adress,
edt_username,
edt_password,
edt_blood,
edt_gender,
edt_level;
Button btn_regs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
edt_username = (EditText) findViewById(R.id.edit_username);
edt_password = (EditText) findViewById(R.id.edit_password);
edt_adress = (EditText) findViewById(R.id.edit_adress);
edt_egn = (EditText) findViewById(R.id.edit_egn);
edt_fam = (EditText) findViewById(R.id.edit_family);
edt_first = (EditText) findViewById(R.id.edit_first);
edt_phone = (EditText) findViewById(R.id.edit_phone);
edt_mid = (EditText) findViewById(R.id.edit_mid);
edt_blood = (EditText) findViewById(R.id.edit_adress2);
edt_gender = (EditText) findViewById(R.id.edit_adress3);
edt_level = (EditText) findViewById(R.id.edit_first2);
btn_regs = (Button)findViewById(R.id.btn_register);
btn_regs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerUser();
}
});
}
private void registerUser() {
try {
Account account = new Account();
account.setP_address(edt_adress.getText().toString());
account.setP_blood_group(edt_blood.getText().toString());
account.setP_first_name(edt_first.getText().toString());
account.setP_mid_name(edt_mid.getText().toString());
account.setP_family_name(edt_fam.getText().toString());
account.setP_gender(edt_gender.getText().toString());
account.setP_phone(edt_phone.getText().toString());
account.setP_egn(edt_egn.getText().toString());
account.setU_password(edt_password.getText().toString());
account.setU_username(edt_username.getText().toString());
account.setU_user_level(edt_level.getText().toString());
INodeJS accountservice = RetrofitClient.getInstance().create(INodeJS.class);
Call call = accountservice.create(account);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
Boolean result = (Boolean) response.body();
if(result){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), getString(R.string.app_name), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call call, Throwable t) {
Toast.makeText(getApplicationContext(), getString(R.string.app_name), Toast.LENGTH_SHORT).show();
}
});
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
xml格式
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity">
<EditText
android:id="@+id/edit_first"
android:layout_width="141dp"
android:layout_height="59dp"
android:layout_marginStart="135dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="135dp"
android:ems="10"
android:hint="Име"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/edit_first2"
android:layout_width="141dp"
android:layout_height="59dp"
android:layout_marginStart="5dp"
android:layout_marginTop="52dp"
android:ems="10"
android:hint="Име"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/edit_first"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/edit_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="102dp"
android:layout_marginTop="18dp"
android:layout_marginEnd="100dp"
android:ems="10"
android:hint="Телефонен номер"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_family" />
<Button
android:id="@+id/btn_register"
android:layout_width="432dp"
android:layout_height="56dp"
android:layout_marginTop="20dp"
android:text="Регистрация"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.523"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_passwords" />
<EditText
android:id="@+id/edit_mid"
android:layout_width="211dp"
android:layout_height="49dp"
android:layout_marginStart="100dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="100dp"
android:ems="10"
android:hint="Презиме"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_first" />
<EditText
android:id="@+id/edit_adress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ems="10"
android:hint="Адрес"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_egn" />
<EditText
android:id="@+id/edit_adress2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:ems="10"
android:hint="Адрес"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_egn" />
<EditText
android:id="@+id/edit_adress3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:ems="10"
android:hint="Адрес"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_egn" />
<EditText
android:id="@+id/edit_passwords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="103dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="99dp"
android:ems="10"
android:hint="Парола"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_usernames" />
<EditText
android:id="@+id/edit_family"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="101dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="101dp"
android:ems="10"
android:hint="Фамилия"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_mid" />
<EditText
android:id="@+id/edit_usernames"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="103dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="99dp"
android:ems="10"
android:hint="Потребителско име"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_adress3" />
<EditText
android:id="@+id/edit_egn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="103dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="99dp"
android:ems="10"
android:hint="ЕГН"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_phone" />
</androidx.constraintlayout.widget.ConstraintLayout>
暂无答案!
目前还没有任何答案,快来回答吧!