简体   繁体   English

firebase android用户数据库注册错误

[英]firebase android user database Sign up Error

I was doing this tutorial on Android and Firebase but for some reason when I try to register a new driver it doesn't interact with Firebase at all. 我在Android和Firebase上进行本教程,但是由于某些原因,当我尝试注册新驱动程序时,它根本无法与Firebase交互。 Though it does show it's connected to Firebase: 尽管确实显示它已连接到Firebase:

通讯btwn App和Firebase

I have downgraded my API to 26 because of this error: 由于此错误,我将API降级为26:

Google Play services out of date. Google Play服务已过时。 Requires 9256000 but found 9080470. 需要9256000,但找到9080470。

So I installed Genymotion to solve this issue as advised by contributors on this platform. 因此,根据该平台上的贡献者的建议,我安装了Genymotion来解决此问题。

But it still doesn't communicate with Firebase. 但是它仍然无法与Firebase通信。 It returns 0 Errors and yet doesn't work. 它返回0错误,但不起作用。

I've installed GenyMotion but every time I try to run on it's devices it keeps crashing. 我已经安装了GenyMotion,但是每次尝试在其设备上运行时,它总是崩溃。

public class DriverLoginActivity extends AppCompatActivity {
    private EditText mEmail, mPassword;
    private Button mLogin, mRegistration;

    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener firebaseAuthListener;
    private static final String TAG = "Test";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driver_login);

        mAuth = FirebaseAuth.getInstance();

        firebaseAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                if(user!=null){
                    Intent intent = new Intent(DriverLoginActivity.this, 
    MainActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }
        };

        mEmail = findViewById(R.id.email);
        mPassword = findViewById(R.id.password);


        mLogin = findViewById(R.id.login);
        mRegistration = findViewById(R.id.registration);

        mRegistration.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String email = mEmail.getText().toString();
                final String password = mPassword.getText().toString();
                mAuth.createUserWithEmailAndPassword(email, 
    password).addOnCompleteListener(DriverLoginActivity.this, new 
    OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(!task.isSuccessful()){
                            Toast.makeText(DriverLoginActivity.this, "sign up 
    error", Toast.LENGTH_SHORT).show();
                        }else {
                            String user_id = mAuth.getCurrentUser().getUid();
                            DatabaseReference current_user_db = 
  FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(user_id);
                            current_user_db.setValue(true);
                        }
                    }
                });
            }
        });

        mLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String email = mEmail.getText().toString();
                final String password = mPassword.getText().toString();
                mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
                        if(!task.isSuccessful()){
                            Log.d(TAG, "onComplete: Failed=" + task.getException().getMessage());
                            Toast.makeText(DriverLoginActivity.this, "sign up error", Toast.LENGTH_SHORT).show();
                        }

                    }
                });

            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(firebaseAuthListener);
    }
    @Override
    protected void onStop() {
        super.onStop();
        mAuth.removeAuthStateListener(firebaseAuthListener);
    }
}

Here are my build.gradle (app) 这是我的build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "ke.co.wafalmelogistics.wafalme"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.gms:google-services:3.1.0'
    implementation 'com.google.firebase:firebase-core:11.6.0'
    implementation 'com.google.firebase:firebase-database:11.6.0'
    implementation 'com.google.firebase:firebase-auth:11.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}




apply plugin: 'com.google.gms.google-services'

build.gradle (module) build.gradle(模块)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.0'
            classpath 'com.google.gms:google-services:3.1.0'


            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

And here is the Error I keep getting when I try to run the app on GenyMotion; 这是我尝试在GenyMotion上运行应用程序时遇到的错误;

 --------- beginning of crash E/AndroidRuntime: FATAL EXCEPTION: main Process: ke.co.wafalmelogistics.wafalme, PID: 1640 java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)' on a null object reference at com.google.android.gms.internal.zzdtp.zzb(Unknown Source) at com.google.android.gms.internal.zzdtw.zza(Unknown Source) at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(Unknown Source) at ke.co.wafalmelogistics.wafalme.DriverLoginActivity$2.onClick(DriverLoginActivity.java:61) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22429) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

ItI am a learner, any help is appreciated. 我是一名学习者,我们将为您提供任何帮助。

我收到相同的错误,因为我使用的是Emulator ..但当我在真实的设备中尝试使用它时,它工作得很好..希望它也对您有用。

Worked for me using these dependencies: 使用以下依赖项为我工作:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    //NOT DEFAULT BELOW
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile 'com.android.support:design:26.1.0'
    compile 'com.github.rtoshiro.mflibrary:mflibrary:1.0.0'
    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'com.google.firebase:firebase-database:11.2.0'
    compile 'com.google.firebase:firebase-auth:11.2.0'
}

Thank you for all the help. 感谢您的所有帮助。

I have the same problem when I use 'com.google.firebase:firebase-auth:11.6.0' 使用'com.google.firebase:firebase-auth:11.6.0'时,我遇到相同的问题

change to 'com.google.firebase:firebase-auth:11.2.0' ` 更改为'com.google.firebase:firebase-auth:11.2.0'

Try this dependencies: 试试这个依赖:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-crash:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

had the same issue in my project while running in the emulator but I solved this by using this in Android Studio 3.0.1 在模拟器中运行时,项目中存在相同的问题,但我通过在Android Studio 3.0.1中使用此问题解决了

app/build.gradle 应用程序/的build.gradle

compile "com.google.firebase:firebase-auth:9.0.2"

build.gradle ( root directory ) build.gradle(根目录)

classpath 'com.google.gms:google-services:3.0.0'

there setting work for me 在那里为我工作

Looking at https://github.com/firebase/FirebaseUI-Android/issues/1104 . https://github.com/firebase/FirebaseUI-Android/issues/1104 I think this is an acknowledged issue in the SDK that would be resolved in the next 1 or 2 SDK updates. 我认为这是SDK中的一个公认问题,将在接下来的1或2个SDK更新中解决。 A github user called Samstern posts this - 一个名为Samstern的github用户将其发布-

A fix for this bug has been submitted internally, so this should be fixed in the next 1-2 Firebase Auth SDK releases depending on the release cycle. 该错误的修复程序已在内部提交,因此应根据发行周期在以后的1-2 Firebase Auth SDK版本中进行修复。

I am going to close this issue here since there's nothing more FIrebaseUI can do, thanks for everyone who reported it! 由于FIrebaseUI无法做更多的事情,因此我将在这里解决此问题,感谢所有举报的人!

Nonetheless, try the following and see if it works. 尽管如此,请尝试以下方法,看看是否可行。 To repeat what Bob Snyder said - Delete this line from the dependencies block: implementation 'com.google.gms:google-services:3.1.0'. 要重复鲍勃·斯奈德(Bob Snyder)所说的-从依赖项块中删除以下行:实现'com.google.gms:google-services:3.1.0'。 Upgrade your firebase to 11.8.0. 将您的Firebase升级到11.8.0。 So your app's build.gradle should look like something like this. 因此,您应用的build.gradle应该看起来像这样。

 implementation 'com.google.firebase:firebase-core:11.8.0' implementation 'com.google.firebase:firebase-auth:11.8.0' implementation 'com.google.firebase:firebase-messaging:11.8.0' implementation 'com.google.firebase:firebase-storage:11.8.0' implementation 'com.google.firebase:firebase-database:11.8.0' 

Let me know how that goes. 让我知道怎么回事。

I solved this by upgrading Google Play Services in the emulator. 我通过在模拟器中升级Google Play服务解决了这一问题。 It was not necessary to change anything in gradle. 不必更改gradle中的任何内容。

For me works change from compile: 对我来说,工作从编译改变了:

com.google.firebase:firebase-auth:11.8.0

to compile: 编译:

com.google.firebase:firebase-auth:11.2.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android在数据库上注册用户 - Android sign up user on database 手动添加用户,无需在 Firebase 数据库上注册 - Adding user manually without sign-up on Firebase database 使用 Android 进行 Firebase 电子邮件和密码身份验证 - 用户注册 - Firebase Email and Password Authentication with android - User sign up 当用户使用Firebase电子邮件身份验证进行注册时,能否获取用户设备详细信息并将其保存在数据库中? - Is it possible to get and save the user device detail in the database while the user sign up with Firebase email auth? 当新用户使用 Android Studio(java) Firebase 实时数据库注册时,如何使每个用户的数据分开? - How do I make each user's data separate when a new user sign up using Android Studio(java) Firebase Realtime Database? Firebase数据库身份验证注册 - Firebase database authentication sign-up Firebase 注册前验证用户 - Firebase verify user before sign up 如何在登录 Android 时更新 Firebase 用户配置文件? - How to update Firebase user profile on sign in Android? 用户没有退出 firebase android - User is not getting sign out firebase android Android Firebase“ UserProfileChangeRequest”正在运行,但在用户注销并再次登录后无法运行 - Android Firebase “UserProfileChangeRequest” is working, but not after user sign out and sign in again
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM