我的代码在我的Firebase数据库中创建了一个新用户,这意味着createUserWithEmailAndPassword方法正在工作,但该应用程序崩溃之后。
参考:我的代码最初可以正常工作,但是在我的Firebase应用程序项目服务帐户中进行了一些更改之后,代码无法正常工作。
mAuth.createUserWithEmailAndPassword(shopEmail,shopPassword)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
ShopObject newShop = new ShopObject(shopName,shopKeeper,shopLocation,shopEmail,shopPhone,placeAddress,placeLat,placeLon);
db.collection("shops")
.add(newShop)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Toast.makeText(getApplicationContext(),documentReference.getId(),Toast.LENGTH_LONG).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(),"Registration Object Fail",Toast.LENGTH_LONG).show();
}
});
Toast.makeText(getApplicationContext(),"Registration Sucess",Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getApplicationContext(),"Registration Fail",Toast.LENGTH_LONG).show();
}
});
}
我的Gradle文件
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-firestore:17.0.2'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:0)
您的代码似乎没问题。尽管您没有共享logcat错误消息,请尝试以下建议来解决该问题。
确保根据您的项目正确设置Firebase规则。
确保您的代码中没有nullPointer异常,例如在不初始化FirebaseDatabase实例的情况下尝试获取对FirebaseAuth的引用。
由于您使用的是Cloud Firestore,请确保在Firebase控制台中选择Cloud Firestore作为数据库
答案 1 :(得分:0)
我认为您是在Firebase中添加“ ShopObject newShop”对象。
ShopObject newShop = new ShopObject(shopName,shopKeeper,shopLocation,shopEmail,shopPhone,placeAddress,placeLat,placeLon);
db.collection("shops")
.add(newShop)
这不是Firebase支持的数据类型。 您必须将其放入HashMap之类的任何supported data type中,然后添加。