我进入导航栏活动后无法启动空白活动

时间:2019-05-17 23:24:24

标签: android

我启动了一个应用程序,我想启动一个新活动来为数据库创建表格。但是,我似乎无法从具有导航栏的活动切换为空活动。当我运行它并按“添加新降落伞”按钮时,应用程序崩溃。

我已经从启动活动(带有两个按钮的空活动)切换到带有菜单的活动。因此,我知道将其添加到清单中,甚至复制了代码并修改了类和布局的名称。

公共类MainMenu扩展了AppCompatActivity {     TextView textView;

private TextView mTextMessage;
DatabaseHelper mDatabaseHelper;
private Button btnAdd, btnViewData;
private EditText editText;

private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
        = new BottomNavigationView.OnNavigationItemSelectedListener() {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.navigation_chutes:
            { mTextMessage.setText(R.string.title_parachutes);
                return true;}
            case R.id.navigation_jump:
            {mTextMessage.setText(R.string.title_jump);
                return true;}
            case R.id.navigation_settings:
            {mTextMessage.setText(R.string.title_settings);
                return true;}
        }
        return false;
    }
};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);
    mTextMessage = (TextView) findViewById(R.id.message);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    textView = (TextView) findViewById(R.id.text);
}
public void greenDay(View v) {
    startActivity(new Intent(getBaseContext(), NewForm.class));
}

}

1 个答案:

答案 0 :(得分:0)

您必须获取应用程序当前所在位置的上下文才能打开新活动

startActivity(new Intent(**v.getContext()**, NewForm.class));