FirebaseAuthentication.getInstance()导致应用崩溃

时间:2017-04-30 00:38:01

标签: android firebase crash

我正在发帖并检索需要Firebase身份验证的应用。我知道Firebase使用异步方法,以便不在主线程上传递它的功能。但是,所有内容似乎都与FirebaseAuthenticationFireDatabase.getInstance().getReference().child()分开。这造成了很多困难。

我的启动器页面活动..

 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)

1 个答案:

答案 0 :(得分:0)

弄清楚出了什么问题,在我的gradle文件中,无论是存储,数据库还是auth,我都没有firebaseui。此外,我意识到firebase依赖项,firebaseui和play服务之间存在兼容性问题。也许这有助于https://github.com/firebase/FirebaseUI-Android