首页 文章

应用程序在打开导航抽屉时崩溃...没有显示错误...应用程序只是关闭

提问于
浏览
0
package com.example.pratik.womensafety;

import android.content.Intent;

import android.graphics.Typeface;

import android.support.constraint.ConstraintLayout;

import android.support.v4.widget.DrawerLayout;

import android.support.v7.app.ActionBarDrawerToggle;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;

导入com.google.firebase.auth.FirebaseUser;

公共类AccountActivity扩展AppCompatActivity实现View.OnClickListener {

TextView t;
TextView g;
private Button mLogout;
private FirebaseAuth mAuth;

private DrawerLayout mLayout;
private ActionBarDrawerToggle mToggle;

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

    mAuth = FirebaseAuth.getInstance();

    mLayout =(DrawerLayout) findViewById(R.id.drawer);
    mToggle = new ActionBarDrawerToggle(this,mLayout,R.string.open,R.string.close);
    mLayout.addDrawerListener(mToggle);
    mToggle.syncState();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);






    if(mAuth.getCurrentUser() == null){
        finish();
        startActivity(new Intent(this,MainActivity.class));

    }

    FirebaseUser user =mAuth.getCurrentUser();

     t = (TextView) findViewById(R.id.intro);
    Typeface myCustomFont= Typeface.createFromAsset(getAssets(), "fonts/Ostrichfontd.otf");
    t.setTypeface(myCustomFont);

    g= (TextView) findViewById(R.id.welcome);
    g.setTypeface(myCustomFont);

    g.setText("WELCOME " + user.getEmail());

    mLogout = (Button) findViewById(R.id.logoutBtn);

    mLogout.setOnClickListener(this);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if(mToggle.onOptionsItemSelected(item)){

        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    if(v == mLogout){

        mAuth.signOut();
        finish();
        startActivity(new Intent(this,MainActivity.class));
    }
}

}

1 回答

  • 0

    尝试

    startActivity(new Intent(AccountActivity.this,MainActivity.class));
    

    代替

    startActivity(new Intent(this,MainActivity.class));
    

相关问题