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

时间:2019-05-25 08:01:20

标签: java android android-intent project logout

我正在尝试注销我的项目。我希望每当我单击以注销图像时,我都会再次进入我的登录页面。对于登录,我使用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$4.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)

2 个答案:

答案 0 :(得分:1)

您没有初始化firebaseAuth

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

firebaseAuth = FirebaseAuth.getInstance();

答案 1 :(得分:0)

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