注销我的应用程序时出现问题。应用程序不断崩溃

Problem in logout for my app. app keeps on crashing

我正在尝试注销我的项目。我希望每当我单击注销图像时,我都打算再次进入我的登录页面。对于登录,我使用的是 Firebase。但是我已经编写了意图代码,每当我 运行 我的应用程序时,它总是崩溃。 很遗憾,动画(我的项目名称)已停止。

import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;


import com.google.firebase.auth.FirebaseAuth;


public class dashboard extends AppCompatActivity {
    RelativeLayout myLayout;
    AnimationDrawable animationDrawable;

    ImageView imgauto,imgbud,imglimit,imgug,imgsignout;
    FirebaseAuth firebaseAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);
        timing(); ////////// animation



      imgauto = findViewById(R.id.autoimg);
        imgug = findViewById(R.id.ugimg);
       imglimit =findViewById(R.id.limitimg);
       imgsignout=findViewById(R.id.sign_out);
      imgauto.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
             startActivity(new Intent(dashboard.this,view_rooms.class));
           }
        });
      imglimit.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivity(new Intent(dashboard.this,limit_rooms.class));
          }
      });
      imgug.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivity(new Intent(dashboard.this,guidance_new.class));
          }
      });
        imgsignout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                firebaseAuth.signOut();
                finish();
                startActivity(new Intent(dashboard.this,MainActivity.class));
            }
        });
    }
    private void timing(){
        myLayout=findViewById(R.id.dashboard);
        animationDrawable=(AnimationDrawable)myLayout.getBackground();
        animationDrawable.setEnterFadeDuration(2500);
        animationDrawable.setExitFadeDuration(2500);
        animationDrawable.start();

    }
}

那是 logcat:

05-25 13:04:27.429 8730-8730/com.example.animation E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NullPointerException
        at com.example.animation.dashboard.onClick(dashboard.java:55)
        at android.view.View.performClick(View.java:4211)
        at android.view.View$PerformClick.run(View.java:17446)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:5336)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
        at dalvik.system.NativeStart.main(Native Method)

您没有初始化 firebaseAuth

onCreate()方法中,初始化FirebaseAuth实例。

firebaseAuth = FirebaseAuth.getInstance();

您已经创建了一个变量 FirebaseAuth firebaseAuth;,但是您必须初始化 firebaseAuth 变量。在 onCreate 方法下或在访问 firebaseAuth 变量之前初始化变量。写入firebaseAuth = firebaseAuth.getInstance();进行初始化。应用程序崩溃只是因为 firebaseAuthnull