java - getActionBar().setSelectedNavigationItem(position); -


i had nullpointerexception when used method above, instead of getsupportactionbar().setselectednavigationitem(position);

for future reference, how can android studio or intellijidea give me better tip on mistake. havent tried analyze -> inspect code

i received common mistake commonsguy sample demos.

it available in google's own effectivenavigation code sample as:

// set action bar. final actionbar actionbar = getactionbar(); 

here, actionbar stayed null , set

if(actionbar != null)  

statements , code managed run, until changed android support library method: getsupportactionbar()

this example google had managed run without showing me 3 "sections tabs"

your activity should extending appcompatactivity make possible use getsupportactionbar() method. please check if activity's theme not extending noactionbar.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -