I'm trying to make a logout for my project. i want that whenever i click to logout image i intent to my login page again. For login i'm using Firebase. But i have write code for intent and whenever i'm running my app it's keeps crashing. Unfortunately, animation(name of my project) has stopped.
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();
}
}
That's 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)
You didn't initialize firebaseAuth
.
In the onCreate()
method, initialize the FirebaseAuth
instance.
firebaseAuth = FirebaseAuth.getInstance();