该字段不为空时,“注册”按钮将正常工作。如果该字段为空,则应用程序将继续停止。我不知道是什么原因,也没有验证密码,也没有确认密码就确认了密码是否存储在firebase中。谁能帮我。我已在此查询中附加了Java代码和XML代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:orientation="vertical"
android:background="@color/background">
<TextView
android:id="@+id/app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="150sp"
android:layout_marginTop="60sp"
android:layout_marginRight="100sp"
android:layout_marginBottom="30sp"
android:fontFamily="@font/font"
android:text="Sign up"
android:textColor="@color/textColor"
android:textSize="50dp" />
<EditText
android:id="@+id/email"
android:letterSpacing="0.2"
android:layout_below="@id/app"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="30sp"
android:layout_marginLeft="30sp"
android:inputType="textEmailAddress"
android:fontFamily="@font/font"
android:textColor="@color/textColor"
android:hint="@string/mail"
android:textColorHint="@color/textColor"
android:drawableLeft="@drawable/ic_account"/>
<EditText
android:id="@+id/password"
android:letterSpacing="0.2"
android:layout_below="@id/email"
android:layout_marginTop="20sp"
android:drawableLeft="@drawable/ic_lock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginRight="30sp"
android:layout_marginLeft="30sp"
android:textColor="@color/textColor"
android:hint="@string/password"
android:fontFamily="@font/font"
android:textColorHint="@color/textColor"/>
<EditText
android:id="@+id/password1"
android:layout_below="@id/password"
android:layout_marginTop="20sp"
android:letterSpacing="0.2"
android:drawableLeft="@drawable/ic_lock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginRight="30sp"
android:layout_marginLeft="30sp"
android:textColor="@color/textColor"
android:hint="Confirm Password"
android:fontFamily="@font/font"
android:textColorHint="@color/textColor"/>
<Button
android:id="@+id/btnLogin"
android:layout_below="@id/password1"
android:layout_width="100sp"
android:layout_height="50sp"
android:layout_marginLeft="160sp"
android:layout_marginRight="10dp"
android:layout_marginTop="30sp"
android:background="@drawable/shapes"
android:fontFamily="@font/font"
android:text="Sign up"
android:textColor="@color/textColor" />
<TextView
android:id="@+id/errorTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/font"
android:text=""
android:textColor="#FF0000"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20sp"
android:layout_marginLeft="160sp"/>
<TextView
android:id="@+id/noaccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnLogin"
android:layout_gravity="center"
android:layout_marginTop="30sp"
android:layout_marginBottom="10sp"
android:textSize="18sp"
android:layout_marginLeft="275sp"
android:fontFamily="@font/font"
android:text="sign in"
android:textColor="@color/signin" />
<TextView
android:id="@+id/signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnLogin"
android:layout_gravity="center"
android:layout_marginRight="85sp"
android:layout_marginTop="30sp"
android:layout_marginBottom="10sp"
android:textSize="18sp"
android:layout_marginLeft="85sp"
android:fontFamily="@font/font"
android:text="@string/alreadyAcc"
android:textColor="@color/textColor" />
<TextView
android:id="@+id/dash"
android:layout_marginLeft="80sp"
android:layout_below="@id/noaccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dash"
android:layout_gravity="center"
android:layout_marginRight="80sp"
android:layout_marginBottom="10sp"
android:textColor="@color/textColor"
android:fontFamily="@font/font"/>
<TextView
android:id="@+id/dash1"
android:layout_below="@id/dash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signby"
android:layout_marginRight="80sp"
android:textSize="18dp"
android:layout_marginLeft="150sp"
android:layout_gravity="center"
android:layout_marginBottom="10sp"
android:textColor="@color/textColor"
android:fontFamily="@font/font"/>
<ImageView
android:layout_below="@id/dash1"
android:layout_marginLeft="170sp"
android:id="@+id/imageView"
android:layout_marginBottom="50sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/telegram1" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_marginTop="25dp"
android:outlineAmbientShadowColor="@color/textColor"
android:layout_toRightOf="@id/btnLogin"
android:layout_below="@id/password1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" />
这是我的Java代码。我是初学者。请帮助我
package com.devanand.login;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
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 java.util.regex.Pattern;
public class Main2Activity extends AppCompatActivity {
EditText email, pass,cPass;
TextView textView,errorTxt;
Button btnlogin;
FirebaseAuth fAuth;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
textView =findViewById(R.id.noaccount);
email = findViewById(R.id.email);
pass = findViewById(R.id.password);
cPass = findViewById(R.id.password1);
btnlogin =findViewById(R.id.btnLogin);
errorTxt =findViewById(R.id.errorTxt);
fAuth = FirebaseAuth.getInstance();
progressBar = findViewById(R.id.progressBar);
if(fAuth.getCurrentUser()!= null) {
Intent intent = new Intent(Main2Activity.this,after_login_main.class);
finish();
}
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Main2Activity.this,MainActivity.class);
startActivity(intent);
}
});
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String emailTxt = email.getText().toString();
String passTxt = pass.getText().toString();
String cPassTxt = cPass.getText().toString();
if( validEmail(emailTxt) && validPassword(passTxt) && confirmPass(passTxt,cPassTxt))
{
resetError();
}
else
{
setError();
}
progressBar.setVisibility(View.VISIBLE);
//register user in firebase.
fAuth.createUserWithEmailAndPassword(emailTxt,passTxt).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Toast.makeText(Main2Activity.this,"Account created successfully",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Main2Activity.this,after_login_main.class);
startActivity(intent);
}else
{
Toast.makeText(Main2Activity.this,"Try again",Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
private boolean validEmail(String email) {
return checkRegex("[\\w-]+@([\\w-]+\\.)+[\\w-]+",email);
}
private boolean validPassword(String pass) {
return checkRegex("^(?=.*\\d).{4,8}$",pass);
}
private boolean confirmPass(String actualPass,String cPass)
{
return actualPass.equals(cPass);
}
private void setError () {
errorTxt.setVisibility(View.VISIBLE);
errorTxt.setText("Please provide Valid details");
}
private void resetError () {
errorTxt.setVisibility(View.INVISIBLE);
errorTxt.setText("");
}
private boolean checkRegex(String pattern, String input) {
Pattern r = Pattern.compile(pattern);
return r.matcher(input).matches();
}
}
这是我的“注册”页面的日志猫:
2020-04-30 10:59:48.387 4048-4055/? E/art: Failed sending reply to debugger: Broken pipe
2020-04-30 11:00:06.456 4048-4048/com.devanand.login E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.devanand.login, PID: 4048
java.lang.IllegalArgumentException: Given String is empty or null
at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(com.google.firebase:firebase-auth@@19.3.1:288)
at com.devanand.login.Main2Activity$2.onClick(Main2Activity.java:100)
at android.view.View.performClick(View.java:6203)
at android.view.View$PerformClick.run(View.java:23239)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6261)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1064)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)
答案 0 :(得分:0)
用下面的if循环包装代码,该循环检查字段是否为空。
if(!emailTxt .equals(“”)&&!passTxt .equals(“”)&&!cPassTxt .equals(“”))
from maya import cmds
# Define a function that will be called when the slider changes values.
def on_size_slider_changed(value):
source_mesh = "pCube2"
if cmds.objExists(source_mesh): # Check if it exists.
cmds.setAttr("{}.scale".format(source_mesh), value, value, value) # Set its scale.
if cmds.window('mainUI2', exists=True):
cmds.deleteUI
win = cmds.window("mainUI2", title="Bush Generator", widthHeight=(300, 300))
# Layout
cmds.columnLayout(adjustableColumn=True)
cmds.text(label='Bush Generator')
cmds.button(label='Distribute', command='DistributeMesh()')
# Use `changeCommand` to define what function it should call.
leaf_size_slider = cmds.floatSliderGrp(label="Size", field=True, min=0, max=100, value=1, changeCommand=on_size_slider_changed)
# Bush tool
def DistributeMesh():
cmds.loadPlugin("MASH", quiet=True)
import MASH.api as mapi
count = 3000
source_mesh = "pCube2"
scatter_mesh = "pSphere1"
source_shape = cmds.listRelatives(scatter_mesh, children=True)[0]
cmds.select(source_mesh)
mash_network = mapi.Network()
mash_network.createNetwork(name="Test", geometry="Instancer")
# set to use meshes to scatter
cmds.setAttr(mash_network.distribute + ".arrangement", 4)
cmds.setAttr(mash_network.distribute + ".pointCount", count)
# connect mesh
cmds.connectAttr(
source_shape + ".worldMesh[0]",
mash_network.distribute + ".inputMesh",
force=True)
cmds.showWindow(win)
注意:根据您的要求,您应该使用&&或 ||运算符。