getSupportActionBar() NullPointerException
问题 In onCreate() method of activity I have this code for ToolBar : toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); My IDE warms me that getSupportActionBar().setDisplayHomeAsUpEnabled(true); may produce NullPointerException . My question is should I ignore it and how can I fix it anyway? 回答1: The IDE warns you about a potential NullPointerException because there are many cases where the app could throw one. For