2017-12-11 20 views
-3

私はログインとログアウトを許可するアプリがあります。以前ログオフしていたときにアプリをクラッシュさせてしまいました。それでもユーザーはログアウトし、アプリに戻ると再びサインインする必要があります。ログアウトするとアプリがクラッシュする

私は下の方でアクションが起こる下の作成方法に私の全体を追加しました。私はそれだけで

+3

あなたはエラーが何であるかを教えするつもりですか? –

答えて

0

を停止したMSGのビールアプリでクラッシュログアウト押したとき、私は

//view objects 
    private TextView textViewUserEmail; 
    private Button buttonLogout; 

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

     buttonAddProducts = (Button) findViewById(R.id.buttonAddProducts); 
     buttonAddBeverages = (Button) findViewById(R.id.buttonAddBeverages); 
     buttonLogout = (Button) findViewById(R.id.buttonLogout); 
     firebaseAuth = FirebaseAuth.getInstance(); 
     buttonAddProducts.setVisibility(View.GONE); 
     buttonAddBeverages.setVisibility(View.GONE); 

     databaseUsers = FirebaseDatabase.getInstance().getReference("users"); 

     String uid = FirebaseAuth.getInstance().getCurrentUser().getUid(); 
     DatabaseReference currentUserReference = databaseUsers.child(uid); 
     currentUserReference.addValueEventListener(new ValueEventListener() { 
      @Override 
      public void onDataChange(DataSnapshot userSnapshot) { 
       if (userSnapshot.exists()) { 
        User user = userSnapshot.getValue(User.class); 

        if(user.getAdminUser() == true) 
        { 
         buttonAddProducts.setVisibility(View.VISIBLE); 
         buttonAddBeverages.setVisibility(View.VISIBLE); 
        } 
       } 
       else{ 
        Log.i("myInfoTag", "Connection problem"); 
       } 
      } 

      @Override 
      public void onCancelled(DatabaseError databaseError) { 
       throw databaseError.toException(); // don't ignore exceptions 
      } 
     }); 


     //if the user is not logged in 
     //that means current user will return null 
     if(firebaseAuth.getCurrentUser() == null){ 
      //closing this activity 
      finish(); 
      //starting login activity 
      startActivity(new Intent(this, LoginActivity.class)); 
     } 

     //getting current user 
     FirebaseUser user = firebaseAuth.getCurrentUser(); 

     //initializing views 
     textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail); 


     //displaying logged in user name 
     textViewUserEmail.setText("Welcome "+user.getEmail()); 


     buttonLogout.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //logging out the user 
       firebaseAuth.signOut(); 
       //closing activity 
       finish(); 
       //starting login activity 
       startActivity(new Intent(ProfileActivity.this, SignUpActivity.class)); 
      } 
     }); 


    } 

をしないのです重複したか何かを追加しただけで包み次のコードブロックは、即時転送が発生することはありません開始されたアクティビティへの実行そのフローを開始するだけで、実行は次のステートメントに続きます。あなたのケースでは

if(firebaseAuth.getCurrentUser() == null){ 
     //closing this activity 
     finish(); 
     //starting login activity 
     startActivity(new Intent(this, LoginActivity.class)); 
    } 

、次の文の一つは、サインインユーザがいないときNullPointerExceptionを投げれる、user.getEmail()です。

関連する問題