Problem running android HelloTabWidget example - NullPointerException on addTab()

后端 未结 12 1108
陌清茗
陌清茗 2021-01-13 17:17

I\'ve tried the Tab Layout example, and I\'ve also fixed the few typos in the example (and added all the activities to the manifest). However, when I run it on the emulator

12条回答
  •  无人共我
    2021-01-13 17:53

    I was having the same issue. I started the tutorials yesterday and this was the only one to have problems.

    The null pointer is thrown at this line the first time its called

    tabHost.addTab(spec);
    

    turn out the fix was in the manifest XML

    
        
           
            
        
    
    
    
     
     
    

    the last two activities were not present before, and it would fail. I added them (thanks to Ngetha's suggestion above!) and it worked perfectly. For the tutorial's example itself, it would be the three artists, albums, and songs activities that you would need to add

    I guess I learned that every activity needs to be listed in the manifest, makes sense I just didn't think of it while following the example to the T.

    Is it true that this is the case? all activities must be in the manifest?

提交回复
热议问题