Android java.lang.NullPointerException getActionBar ()

I tried to implement an Setting Activity class but it give’s me back an error:

Caused by: java.lang.NullPointerException
            at com.example.andrei.sunshine.SettingsActivity.setupActionBar(SettingsActivity.java:58)
            at com.example.andrei.sunshine.SettingsActivity.onCreate(SettingsActivity.java:48)
            at android.app.Activity.performCreate(Activity.java:5264)

This is the line : getActionBar().setDisplayHomeAsUpEnabled(true);

And the AndroidManifest is :



    
        
            

            
        
    
    
        
    
    
        
    

Please help me

If your SettingsActivity
extend ActionBarActivity
, your getActionBar();
will be available.

public class SettingsActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yourLayout);
        //If you use support library
        //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

See the documentation
for more info.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Android java.lang.NullPointerException getActionBar ()

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录