本文介绍了FirebaseAuth ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  java.lang.RuntimeException:无法恢复活动{com。 example.firebase / com.example.firebase.MainActivity}:java.lang.ClassCastException:com.google.android.gms.b.qf无法在android上转换为com.google.firebase.auth.n 
。 app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
at android.app.ActivityThread.access $ 700(ActivityThread.java:168)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1329)
at android.os。 Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:5493)
在java.lang.reflect.Method.invokeNative(本地方法)$ b $在java.lang.reflect.Method .invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1225)
在com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1041)
在dalvik.system.NativeStart.main(本地方法)
导致:java.lang.ClassCastException:com.google.android.gms.b.qf无法投射通过com.google.android.gms.b.aw.a(未知来源)com.google.firebase.auth.n
(com.google.firebase.auth.FirebaseAuth.b(未知来源)
来源)
在com.google.firebase.auth.FirebaseAuth。< init>(未知来源)
在com.google.firebase.auth.FirebaseAuth。< init>(未知来源)
at com.google.android.gms.b.av。< init>(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.a(Unknown Source)
at com。 google.firebase.auth.FirebaseAuth.b(Unknown Source)
at com.atlascoder.android.dollaruz.MainActivity.onResume(Unknown Source)
at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1209)
at android.app.Activity.performResume(Activity.java:5450)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2922)
。 ..

它发生在我的AppCompatActivity的onResume()回调中:

  ... 

FirebaseAuth mAuth;

@Override
protected void onResume(){
super.onResume();

if(mAuth == null){
mAuth = FirebaseAuth.getInstance();
mAuth.signInAnonymously()addOnCompleteListener(新OnCompleteListener< AuthResult>(){
@覆盖
公共无效的onComplete(@NonNull任务< AuthResult>任务){
FirebaseUser用户= mAuth.getCurrentUser();
如果(!用户= NULL){
setActiveFragment(mActiveFragmentTag);
}否则{
Toast.makeText(MainActivity.this,的getString(R。 To.LASTTH_SHORT).show();
}
}
});
} else {
setActiveFragment(mActiveFragmentTag);



$ b $ / code $ / pre

第一次打电话时不会发生,但是一段时间后我重新打开应用程序。而且,更奇怪的是,即使重新启动应用程序(我的意思是在设备上重新启动,而不是重新安装),我无法打开应用程序。



我的模块的构建。 gradle content:

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
defaultConfig {
applicationIdcom.example.firebase
minSdkVersion 14
targetSdkVersion 23
versionName'1.3 '
vectorDrawables.useSupportLibrary =真
的versionCode 4
}
testOptions {
unitTests.returnDefaultValues =真
}
buildTypes {
$ {
minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
productFlavors {
}
}

依赖关系{
编译fileTree(dir: libs',包括:['* .jar'])
testCompile'junit:junit:4.12'
testCompile'org.mockito:mockito-core:1.10.19'
compile'c​​om .android.support:appcompat-v7:23.3.0'
compile'c​​om.google.android.gms:play-services-ads:9.2.1'
compile'me.grantland:autofittextview:0.2 。+'
compile'c​​om.google.firebase:firebase-auth:9.2.1'
compile'c​​om.google.firebase:firebase-messaging:9.2.1'
compile'c​​om .google.firebase:firebase-database:9.2.1'
compile'c​​om.android.support:cardview-v7:23.3.0'
compile'c​​om.android.support:design:23.3.0 '
}

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

有什么可能是错误的?

解决方案
调用FirebaseAuth.getInstance()。signOut MainActivity在您登录后,您可以尝试它。


I am getting strange exception from deep of Android:

java.lang.RuntimeException: Unable to resume activity {com.example.firebase/com.example.firebase.MainActivity}: java.lang.ClassCastException: com.google.android.gms.b.qf cannot be cast to com.google.firebase.auth.n
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
    at android.app.ActivityThread.access$700(ActivityThread.java:168)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:177)
    at android.app.ActivityThread.main(ActivityThread.java:5493)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.google.android.gms.b.qf cannot be cast to com.google.firebase.auth.n
    at com.google.android.gms.b.aw.a(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.b(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
    at com.google.android.gms.b.av.<init>(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.a(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.b(Unknown Source)
    at com.atlascoder.android.dollaruz.MainActivity.onResume(Unknown Source)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1209)
    at android.app.Activity.performResume(Activity.java:5450)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2922)
...

And it occurs within the onResume() callback for my AppCompatActivity:

...

FirebaseAuth mAuth;

@Override
protected void onResume(){
    super.onResume();

        if (mAuth == null) {
            mAuth = FirebaseAuth.getInstance();
            mAuth.signInAnonymously().addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    FirebaseUser user = mAuth.getCurrentUser();
                    if (user != null) {
                        setActiveFragment(mActiveFragmentTag);
                    } else {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_cant_auth_firebase), Toast.LENGTH_SHORT).show();
                    }
                }
            });
        } else {
            setActiveFragment(mActiveFragmentTag);
        }
}

...

It occurs no when first called but when I reopen the app after some time. And, what is more strange, I can't open the app even after restarting of the app (I mean restarting on device and not reinstalling).

My module's build.gradle content:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '24.0.0'
    defaultConfig {
        applicationId "com.example.firebase"
        minSdkVersion 14
        targetSdkVersion 23
        versionName '1.3'
        vectorDrawables.useSupportLibrary = true
        versionCode 4
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.android.gms:play-services-ads:9.2.1'
    compile 'me.grantland:autofittextview:0.2.+'
    compile 'com.google.firebase:firebase-auth:9.2.1'
    compile 'com.google.firebase:firebase-messaging:9.2.1'
    compile 'com.google.firebase:firebase-database:9.2.1'
    compile 'com.android.support:cardview-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
}

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

What could be wrong?

解决方案

call FirebaseAuth.getInstance().signOut() in onDestroy of MainActivity after you sign in, you can try it.

这篇关于FirebaseAuth ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 22:10