why null value display in actionbar in android? -
i making simple demo of tab view .but on first line getting null pointer exception . getting null value method getactionbar()
why ? share class
import android.app.actionbar; import android.app.fragmenttransaction; import android.os.bundle; import android.support.v4.app.fragmentactivity; public class mainactivity extends fragmentactivity implements actionbar.tablistener { actionbar actionbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); actionbar=getactionbar(); /// <- line causing issue actionbar.setnavigationmode(actionbar.navigation_mode_tabs); } // ---------- methods ---------------// }
i null value on line actionbar=getactionbar();
here manifest file , style.xml
<resources> <!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light"> <!-- customize theme here. --> </style> </resources>
app.grudle
apply plugin: 'com.android.application' android { compilesdkversion 22 buildtoolsversion "22.0.1" defaultconfig { applicationid "com.example.naveen.tabviewswipe" minsdkversion 15 targetsdkversion 22 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' }
if want extend fragmentactivity, need use non-appcompat theme i.e. holo actionbar
<!-- base application theme. --> <style name="apptheme" parent="android:theme.holo"> <!-- customize theme here. --> </style>
Comments
Post a Comment