Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:25:48+00:00 2026-05-27T12:25:48+00:00

I couldnt figure out this one. I am customizing my ActionBar (and yes my

  • 0

I couldnt figure out this one. I am customizing my ActionBar (and yes my App is for 3.0+) The code runs fine on Device(using Motorola xoom ,if it matters) .But when i run this on Emulator it throws NPE.This is my code for ActionBar

/**
 * Customizes Action bar sets background color and assigns a layout to it
 */
private void customActionBar() {
    Log.v(TAG, "customizing ActionBar Entry");
    ActionBar actionBar = getActionBar();
    Log.v(TAG, "customizing ActionBar : "+actionBar.toString());
            //This is where i get NPE
    actionBar.setBackgroundDrawable(new ColorDrawable(Color
            .parseColor(Constants.COLOR)));
    Log.v(TAG, "customizing ActionBar -Background color : ");

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.custom_action, null);
    // lay.setLayoutParams(new ActionBar.LayoutParams(
    // android.app.ActionBar.LayoutParams.MATCH_PARENT,
    // android.app.ActionBar.LayoutParams.MATCH_PARENT));
    actionBar.setCustomView(view);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    Log.v(TAG, "customizing ActionBar Exit");
}

EDIT : logcat

V/>>> FullPdfViewerActivity(438): customizing ActionBar Entry
D/AndroidRuntime(438): Shutting down VM
W/dalvikvm(438): threadid=1: thread exiting with uncaught exception (group=0x40014760)
E/AndroidRuntime(438): FATAL EXCEPTION: main
E/AndroidRuntime(438): java.lang.RuntimeException: Unable to start activity                                 
ComponentInfo{com.test.android.tester/com.test.android.tester.core.AwesomePagerActivity}:          java.lang.NullPointerException
E/AndroidRuntime(438):  at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
E/AndroidRuntime(438):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
E/AndroidRuntime(438):  at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(438):  at    android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
E/AndroidRuntime(438):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(438):  at android.os.Looper.loop(Looper.java:126)
E/AndroidRuntime(438):  at android.app.ActivityThread.main(ActivityThread.java:3997)
E/AndroidRuntime(438):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(438):  at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(438):  at   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime(438):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime(438):  at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(438): Caused by: java.lang.NullPointerException
E/AndroidRuntime(438):  at com.test.android.tester.core.AwesomePagerActivity.customActionBar(AwesomePagerActivity.java:227)
E/AndroidRuntime(438):  at com.test.android.tester.core.AwesomePagerActivity.onCreate(AwesomePagerActivity.java:187)
E/AndroidRuntime(438):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
E/AndroidRuntime(438):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
E/AndroidRuntime(438):  ... 11 more

I call this from my onCreate() .I am worried if it will work for other devices??

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:25:49+00:00Added an answer on May 27, 2026 at 12:25 pm

    I think, that getActionBar() returns null. I saw this behavior when getActionBar() was called before setContentView() of activity, but only on Android 3.0 and 3.1, on Android 3.2 order does not matter.
    Try to call setContentView before customizing action bar

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I can't figure this one out for the life of me. I'm using
I have been scouring the internet trying to figure this one out. Any ideas
I know this one might be easy but I couldn't figure out. I have
I have been trying to figure this one out but I am having a
I can't figure this out, and couldn't find a solution after googling around. I'm
Maybe it's easy, but I couldn't really figure this out right so far... I
I guess this is simple, but i couldnot figure it out. i have a
This is a simple question,I guess, but I couldn't figure it out. How do
This is something I just couldn't figure out how to do in ASP.NET: I
Sorry, but I can't figure this out from the Python documentation or any of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.