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

时间:2018-08-16 21:36:19

标签: android android-studio uinavigationbar

package com.example.pratik.womensafety;

导入android.content.Intent;

import android.graphics.Typeface;

导入android.support.constraint.ConstraintLayout;

导入android.support.v4.widget.DrawerLayout;

导入android.support.v7.app.ActionBarDrawerToggle;

导入android.support.v7.app.AppCompatActivity;

导入android.os.Bundle;

import android.view.MenuItem;

导入android.view.View;

import android.widget.Button;

导入android.widget.TextView;

导入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 :(得分:0)

尝试

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

代替

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