How to Use the actionbar in the V7 package

Source: Internet
Author: User

================================= Problem description ========================== =
I strictly follow the steps of the android official website to import the android-support-v7-appcompat library project, and then create a new project, introduce this library project, compilation is no problem.
However, the following problems are reported during the migration,

Java. Lang. runtimeexception: unable to start activity componentinfo {com. example. actionbarlower/COM. example. actionbarlower. mainactivity}: Java. Lang. nullpointerexception
At Android. App. activitythread. javasmlaunchactivity (activitythread. Java: 2295)
At Android. App. activitythread. handlelaunchactivity (activitythread. Java: 2349)
At Android. App. activitythread. Access $700 (activitythread. Java: 159)
At Android. App. activitythread $ H. handlemessage (activitythread. Java: 1316)
At Android. OS. handler. dispatchmessage (handler. Java: 99)
At Android. OS. lorule. Loop (lorule. Java: 176)
At Android. App. activitythread. Main (activitythread. Java: 5419)
At java. Lang. Reflect. method. invokenative (native method)
At java. Lang. Reflect. method. Invoke (method. Java: 525)
At com. Android. Internal. OS. zygoteinit $ methodandargscaller. Run (zygoteinit. Java: 1209)
At com. Android. Internal. OS. zygoteinit. Main (zygoteinit. Java: 1025)
At Dalvik. system. nativestart. Main (native method)
Caused by: Java. Lang. nullpointerexception
At Android. Support. v7.app. actionbarimplics. setdisplayshowhomeenabled (actionbarimplics. Java: 169)
At Android. Support. v7.app. actionbarimpljb. setdisplayshowhomeenabled (actionbarimpljb. Java: 20)
At com. example. actionbarlower. mainactivity. oncreate (mainactivity. Java: 20)
At Android. App. activity. javasmcreate (activity. Java: 5372)
At Android. App. instrumentation. callactivityoncreate (instrumentation. Java: 1104)
At Android. App. activitythread. javasmlaunchactivity (activitythread. Java: 2257)
... 11 more

The Code is as follows:
Public class mainactivity extends actionbaractivity {

Private actionbar supportactionbar;

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main );

Supportactionbar = getsuppactionactionbar ();
Supportactionbar. setdisplayshowhomeenabled (true );

}

@ Override
Public Boolean oncreateoptionsmenu (menu ){
Getmenuinflater (). Inflate (R. Menu. Main, menu );
Return super. oncreateoptionsmenu (menu );
}

}


Manifest is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. example. actionbarlower"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">

<Uses-SDK
Android: minsdkversion = "8"
Android: targetsdkversion = "9"/>

<Application
Android: allowbackup = "true"
Android: icon = "@ drawable/ic_launcher"
Android: Label = "@ string/app_name"
Android: theme = "@ style/apptheme">
<Activity
Android: Name = "com. example. actionbarlower. mainactivity"
Android: Label = "@ string/app_name"
Android: theme = "@ style/theme. appcompat. Light">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>

<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>

</Manifest>



The Null Pointer Points to supportactionbar. setdisplayshowhomeenabled (true); this line, but it is not empty to print suppactionactionbar in front.

=============================== Solution 1 ========================== ===
Android: minsdkversion and Android: targetsdkversion are changed to 10 and 15 respectively.

How to Use the actionbar in the V7 package

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.