当我按下注册按钮时,它继续显示错误,如注册失败
这是我的Javacode
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PatternMatcher;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;
public class RegisterUser extends AppCompatActivity implements View.OnClickListener{
private TextView banner, registerUser,alreadyhaveaacount;
private EditText editTextFullname, editTextAge,editTextEmail,editTextPassword;
private ProgressBar progressBar;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_user);
mAuth= FirebaseAuth.getInstance();
banner =(TextView) findViewById(R.id.banner);
banner.setOnClickListener(this);
alreadyhaveaacount=findViewById(R.id.alreadyhave);
alreadyhaveaacount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RegisterUser.this, MainActivity.class);
startActivity(intent);
}
});
registerUser= (Button) findViewById(R.id.registerUser);
registerUser.setOnClickListener(this);
editTextFullname =(EditText)findViewById(R.id.fullname);
editTextAge =(EditText)findViewById(R.id.age);
editTextEmail =(EditText)findViewById(R.id.email);
editTextPassword =(EditText)findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.banner:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.registerUser:
registerUser();
break;
}
}
private void registerUser() {
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
String age = editTextAge.getText().toString().trim();
String fullname = editTextFullname.getText().toString().trim();
if(fullname.isEmpty()){
editTextFullname.setError("Fullname is Required!");
editTextFullname.requestFocus();
return;
}
if(fullname.length()>50){
editTextFullname.setError("Input cannot be lower than 50!");
editTextFullname.requestFocus();
return;
}
if(password.isEmpty()){
editTextPassword.setError("Password is Required!");
editTextPassword.requestFocus();
return;
}
if(password.length()<6){
editTextPassword.setError("Password is too short!");
editTextPassword.requestFocus();
return;
}
if(age.isEmpty()){
editTextAge.setError("Age is Required!");
editTextAge.requestFocus();
return;
}
if(age.length()>3){
editTextAge.setError("Age cannot be higher than 3 digits!");
editTextAge.requestFocus();
return;
}
if(email.isEmpty()){
editTextAge.setError("Email is required!");
editTextAge.requestFocus();
return;
}if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
editTextEmail.setError("Please Provide a valid email!");
editTextEmail.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
USer user = new USer(fullname,age,email,password);
FirebaseDatabase.getInstance().getReference("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText(RegisterUser.this, "User has been registered succesfully", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}else{
Toast.makeText(RegisterUser.this, "Failed To Registered! Try Again", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});
}else{
Toast.makeText(RegisterUser.this, "Failed To Registered! Try Again", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
}
这是我Register_User.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:background="#8BC34A"
tools:context=".RegisterUser"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/banner"
android:layout_width="271dp"
android:layout_height="50dp"
android:layout_marginStart="176dp"
android:layout_marginLeft="176dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="177dp"
android:layout_marginRight="177dp"
android:fontFamily="sans-serif-black"
android:gravity="center_horizontal"
android:text="Plantured"
android:textAlignment="center"
android:textSize="40dp"
android:textColor="@color/black"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/registerUser"
android:layout_width="380dp"
android:layout_height="70dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:backgroundTint="#D322D60E"
android:text="Register"
android:textColor="#ffffff"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.492"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout5"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/alreadyhave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="Already have an account Login Here!"
android:textColor="@color/black"
android:textSize="23dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerUser" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:hint="Fullname"
app:hintTextColor="@color/black"
android:paddingTop="5dp"
app:counterEnabled="true"
app:counterTextColor="@color/black"
app:counterMaxLength="50"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner"
app:startIconDrawable="@drawable/ic_baseline_person_24">
<com.google.android.material.textfield.TextInputEditText
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:id="@+id/fullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:inputType="text"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black"
android:textSize="20sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout2"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:hint="Age"
app:hintTextColor="@color/black"
app:counterTextColor="@color/black"
app:counterEnabled="true"
app:counterMaxLength="3"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
app:startIconDrawable="@drawable/ic_baseline_person_24">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:inputType="number"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black"
android:textSize="20sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout3"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:hint="Password"
app:counterEnabled="true"
app:counterMaxLength="15"
app:counterTextColor="@color/black"
app:endIconMode="password_toggle"
app:layout_constraintEnd_toEndOf="parent"
app:hintTextColor="@color/black"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout2"
app:startIconDrawable="@drawable/ic_baseline_lock_24">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:inputType="textPassword"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black"
android:textSize="20sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout5"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:hint="Email"
app:counterTextColor="@color/black"
app:counterEnabled="true"
app:counterMaxLength="40"
app:hintTextColor="@color/black"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout3"
app:startIconDrawable="@drawable/ic_baseline_email_24">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:inputType="textEmailAddress"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black"
android:textSize="20sp" />
</com.google.android.material.textfield.TextInputLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
**这是用户类**
public class USer {
public String fullName, age, email,password;
public USer(){
}
public USer(String fullName, String age,String email,String password){
this.fullName = fullName;
this.age=age;
this.email=email;
this.password=password;
}
}
这是build.gradle(Project: App)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
// Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是gradle.build(模块:app)
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.authapp"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.mlkit:image-labeling:17.0.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
apply plugin: 'com.google.gms.google-services'
这是我的firebase实时数据库的路径
在此处输入图像描述
每当我单击登录页面中的“注册”按钮时,应用程序就会崩溃,无法移动到下一个活动。我已经在这个问题上纠缠了一天,似乎在任何地方都找不到解决办法。 下面是我为注册按钮方法编写的代码。(和是文本输入布局) Logcat在第7行显示错误,即ref.child(…行)。我尝试了第7行的替代方法,如:
如果我按下呼叫按钮,我会得到一个错误,即出租车没有呼叫,而是转到另一个窗口。 我认为这个错误来自实时数据库。如果你有不同的意见,写下你的答案。 错误:E/AndroidRuntime:致命异常:主进程:com。实例乌兹别克斯坦,PID:8915爪哇。lang.NullPointerException:尝试调用虚拟方法“double android”。地方地方getLatitude()'位于com上
我已经创建了一个webview应用程序。按音量键时,我的应用程序崩溃。这是logcat中的错误 W/ViewRootImpl[MainActivity]:由于没有窗口焦点而取消事件:KeyEvent{action=action\u UP,keyCode=keyCode\u VOLUME\u DOWN,scanCode=114,metaState=0,flags=0x28,repeatCount=0
这是我的XML代码 这是我的Java代码
请求注册请求时出错。 路由器的req.body也打印正确 我认为创建时发生了错误 back/routes/user.js 控制台打印错误消息 错误:XMLHttpRequest的createError(createError.js:16)处出现网络错误。handleError(xhr.js:81) 岗位http://localhost:3065/api/usernet::ERR\u EMPTY\u
经过几天的计划,我刚刚开始为我的聊天应用程序编写一些代码,但问题是,在Gradle Build完成并将应用程序安装在我的设备上之后,它一直在崩溃。我创建了一个预计会打开新活动的按钮,但它没有这样做,而是崩溃了。在我编写任何代码之前,一切都正常,应用程序打开,logcat没有显示任何错误。以下是错误: 我试着遵循其他一些建议,但都不起作用。以下是我的代码片段: }