gpt4 book ai didi

android - FirebaseAuthentication.getInstance() 导致应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 09:56:37 24 4
gpt4 key购买 nike

我正在制作一个需要 Firebase 身份验证的发布和检索应用。我知道 Firebase 使用异步方法,以免在主线程上传递其函数。然而,除了 FirebaseAuthentication 和 FireDatabase.getInstance().getReference().child() 之外,一切似乎都正常工作。这造成了很多困难。

我的启动器页面 Activity ..

 package com.gmail.peeman34.eglisaofficial;


//private Button eglisasignupbutton;
//Handler handler = null;

public EGLISA_OFFICIAL() {
super();
}
//}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eglisa_official);


Thread timer = new Thread() {

@Override
public void run() {

try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}

Intent openStartingPoint = new Intent(EGLISA_OFFICIAL.this, BRIDGE.class);
startActivity(openStartingPoint);
finish();

}
};
timer.start();
}

}

这是我的页面,为您提供是否登录或注册的按钮。在这种情况下注册:

package com.gmail.peeman34.eglisaofficial;

public class BRIDGE extends AppCompatActivity {
private Button signituphere;
private Button signitinhere;
Handler firsthandler = new Handler();
Thread mythread;
Handler handler;
Intent peethread;
public BRIDGE() {
super();
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bridge);


signituphere = (Button) findViewById(R.id.signituphere);


Button signitinhere = (Button) findViewById(R.id.signituphere);

Thread mythread = new Thread(new Mythread());
mythread.start();


}

public void startLogin(View view){
handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
peethread = new Intent(BRIDGE.this, ActivityMaiin.class);

startActivity(peethread);

}
});


}


class Mythread extends Thread {


private Handler handler;

public Mythread() {

}

@Override
public void run() {


try {


sleep(10000);

Looper.prepare();
handler = new Handler();
Looper.loop();


} catch (InterruptedException e) {
e.printStackTrace();
}




}



}

}

这是注册页面无法正常工作,因为 FirebaseAuthenticationFireDatabaseReference().getInstance().getReference().child() 不断使我的应用程序加载并崩溃。

 package com.gmail.peeman34.eglisaofficial;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.google.android.gms.appdatasearch.RegisterSectionInfo;
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.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;


import static com.gmail.peeman34.eglisaofficial.R.string.view;

/**
* Created by pee on 6/1/2016.
*/

public class ActivityMaiin extends AppCompatActivity {


private EditText Namefield;
private EditText Emailfied;
private EditText Passwordfield;
private Button mRegistration;
private ProgressDialog mProgress;
ImageButton Loginthebutton;
Intent AccountSetup;

Handler africanhandler;
Handler thefirsthandler;
Thread firstthread;
Thread secondthread;

private FirebaseAuth mAuth;

private DatabaseReference mDatabase;


public ActivityMaiin() {
super();
}


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity22);

Namefield = (EditText) findViewById(R.id.username);
Emailfied = (EditText) findViewById(R.id.email);
Passwordfield = (EditText) findViewById(R.id.password);

mAuth = FirebaseAuth.getInstance();
mDatabase=FirebaseDatabase.getInstance().getReference().child("Users");


mRegistration = (Button) findViewById(R.id.signupbutton);
Loginthebutton = (ImageButton) findViewById(R.id.loginthebutton);
mProgress = new ProgressDialog(this);


firstthread = new Thread(new Myfirstthread());

firstthread.start();

secondthread.start();





mRegistration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

try {

startRegister();



}catch (Exception e){

}
}
});






}







public void startaccountsetup() {

thefirsthandler = new Handler();

thefirsthandler.post(new Runnable() {


@Override
public void run() {


Intent setuptheaccount = new Intent(ActivityMaiin.this,
ACCOUNTSETUP.class);
startActivity(setuptheaccount);


}





});

}

               class  Myfirstthread extends Thread{
public Myfirstthread() {
super();
}


@Override
public void run() {
/* try {
sleep(10000);

} catch (InterruptedException e) {
e.printStackTrace();


}*/


Looper.prepare();

Looper.loop();
}
}









public void startRegister() throws InterruptedException {


final String name = Namefield.getText().toString().trim();
String email = Emailfied.getText().toString().trim();
String password = Passwordfield.getText().toString().trim();

if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email)
&& !TextUtils.isEmpty(password)) {
mProgress.setMessage("Signing up");
mProgress.show();


try {

mAuth.createUserWithEmailAndPassword(email,
password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {

String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db = mDatabase.child(user_id);

current_user_db.child("name").setValue(name);
current_user_db.child("image").setValue("default");

mProgress.dismiss();



startaccountsetup();
}


}

});
} catch (Exception e) {

}

}


}

}

这是我的堆栈跟踪,在某种程度上非常明显。忘记处理程序吧。我担心 Firebase 实例。处理程序工作得很好。由于我一直在尝试和犯错,它们的排列有点困惑。

FATAL EXCEPTION: main
Process: com.gmail.peeman34.eglisaofficial, PID: 23807
java.lang.IncompatibleClassChangeError: com.google.firebase.zza
at com.google.android.gms.internal.zzbiu.<init>(Unknown Source)
at com.google.android.gms.internal.zzbjc.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zzb(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
at com.google.android.gms.internal.zzbkg.<init>(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zzd(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zzc(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
at com.gmail.peeman34.eglisaofficial.ActivityMaiin.onCreate(ActivityMaiin.java:67)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

最佳答案

找出问题所在,在我的 gradle 文件中,无论是用于存储、数据库还是身份验证,我都没有 firebaseui。我还意识到 firebase 依赖项、firebaseui 和 play 服务之间存在兼容性问题。也许这可能有帮助https://github.com/firebase/FirebaseUI-Android

关于android - FirebaseAuthentication.getInstance() 导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43701781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com