Summary of Workarounds for "Android" Getactionbar () null

Source: Internet
Author: User

Objective

When using ActionBar, there are sometimes empty pointer exceptions, which is due to the fact that the application is not getting to ActionBar, and that the application is not getting to ActionBar more. So let's summarize the causes of the errors that ActionBar can't get.

How to Solve
  1. Check if your app is set up without ActionBar topic theme . Or if you set the Noactionbar or Notitlebar property directly, check these points primarily: check the Theme property in the tag in Androidmanifest.xml. Then check if there are different Theme in each Activity tab causing the ActionBar of this interface to not display, @android: Style/theme.notitlebar and <item Name= "Windowactionbar" >false</item>
    <item name= "Android:windownotitle" >true</item>
    This property will cause the Actionbar in your app to disappear, remember. If you want to use Actionbar, be sure to clear these theme property settings, assuming that the Res folder in your project is in addition to the values folder. There are other res/values-v11,style/values-v14 and so on, then the styles.xml in these folders need to be checked, and finally check whether the activity code is dynamically set to full screen or do not display titlebar, Code such as the following:
    //requestwindowfeature (window.feature_no_title);
    //getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_ fullscreen);

    The above two lines of code. The above sentence set activity does not display titlebar, the next sentence set activity to full-screen mode, both code will cause ActionBar
    cannot display, so that Getactionbar () get failed, assuming that your project Activity has the parent level of activity, you also need to the parent level of activity in the Notitle and full-screen code to stare out.
  2. Let's say you're not sure if the theme Theme your app supports ActionBar and can be set to Theme.appcompatin the Res/values.xml file, AppCompat theme in Theme. To ensure that the low version of Android can also be used ActionBar (Note: Res/values,res/values-v11,res/values-v14 folder style is set to style, Also note: Do not set to 1th in the topic that will prohibit ActionBar display, but can be set to different kinds of topics, in addition, in acticity to get ActionBar (Getactionbar () or Getsupportbar ()), Need to be called after Setcontentview (R.layout.main).
  3. Assuming your project is using Android.app.ActionBar, you need to change your app's minimum support version number to one (Android 3.0)and use Getactionbar () to get ActionBar , assuming your project supports Android 3.0 or less, your project needs to introduce the latest AppCompat Compatibility Pack, and then change the ActionBar reference to Android.support.v7.app.ActionBar , and use Getsupportactionbar to obtain ActionBar;
  4. There are other reasons why Getactionbar () failed to get a ActionBar, such as when I was searching the Internet. Someone's project was created on Android SDK 2.2, when he used ActionBar to set androidmanifest.xml in Minsdkversion to 11 (), found Getactionbar () The get failure is due to the absence of res/values-v11 and Res/values-v14 and the Style.xml files in the project. My recent encounter with Getactionbar () is null to import a project that someone sent me in Eclipse, but the apk Getactionbar () that was compiled on his computer, but not on my computer, tried several methods above, and finally, I've imported this project into Android Studio and I'm finally able to execute it properly.

Suppose you have other questions about Getactionbar () null, methods and experiences. Welcome to discuss communication.

References link

Http://vcsos.com/Article/pageSource/150125/20150125093506.shtml
http://stackoverflow.com/questions/27959107/getting-the-null-pointer-exception-in-the-getactionbar-method/27960390
Http://www.apkbus.com/android-130755-1-1.html
Http://www.cnblogs.com/shortboy/archive/2013/04/18/3029029.html
Http://stackoverflow.com/questions/6867076/getactionbar-returns-null
http://blog.csdn.net/yueqinglkong/article/details/39577749
Http://stackoverflow.com/questions/8499181/actionbar-throws-nullpointerexception
Http://stackoverflow.com/questions/28255552/nullpointerexception-caused-by-getactionbar

Summary of Workarounds for "Android" Getactionbar () null

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.