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 7889533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:07:26+00:00 2026-06-03T06:07:26+00:00

I use a spinner in my ListActivity and get a NullPointerException at setAdapter method.

  • 0

I use a spinner in my ListActivity and get a NullPointerException at setAdapter method. I tried to research similar issues on google and stackoverflow and tried their advice but no use. However, this code works in another app of mine.

options = getResources().getStringArray(R.array.options_array);
Spinner s1 = (Spinner) findViewById(R.id.spinner1);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_spinner_dropdown_item, options);

s1.setAdapter(adapter); // Here is the error
s1.setOnItemSelectedListener(new OnItemSelectedListener()
    {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
        {
            int index = arg0.getSelectedItemPosition();
            Toast.makeText(getBaseContext(), 
                "You have selected item : " + options[index], 
                Toast.LENGTH_SHORT).show();                
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {} 
    }); 

My spinner xml

    <Spinner    
        android:id="@+id/spinner1"    
        android:layout_width="25dip"
        android:layout_height="25dip"
            android:entries="@array/options_array"
        android:prompt="@string/spin_prompt"
        android:background="@drawable/expander_ic_maximized"
        android:layout_alignParentRight="true" 
            android:layout_below="@id/name_text"        
        />  

LogCat

05-04 09:23:48.492: ERROR/AndroidRuntime(343): Caused by: java.lang.NullPointerException

05-04 09:23:48.492: ERROR/AndroidRuntime(343):     at com.amannain.android.missedcalls.MissedCallsSpinActivity.runSpinner(MissedCallsSpinActivity.java:31)

05-04 09:23:48.492: ERROR/AndroidRuntime(343):     at com.amannain.android.missedcalls.MissedCallsSpinActivity.onCreate(MissedCallsSpinActivity.java:21)
  • 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-06-03T06:07:28+00:00Added an answer on June 3, 2026 at 6:07 am

    are you setting the following in your activity where you have defined your spinner
    setContentView(R.layout.main);
    this main.xml should have your spinner component defined with id “spinner1”

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

Sidebar

Related Questions

I'm trying to use the following to create a Spinner . But I get
I use two Spinner in my App. One of them is initially disabled because
I am trying to use the jQuery UI 1.9 spinner for the quantity field
I have a problem with my ListActivity, i use a thread to show a
i want to use Android spinner with following data. Spinner will display only text
I want to use a Spinner that initially (when the user has not made
I need to use the JQuery spinner for hours so the template will be:
I use this code to generate a spinner in my app: subCatAdapter = new
For an Android application, I'm trying to use a Spinner which, when an option
I use setOnItemSelectedListener on a spinner. The listener is triggered if I change the

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.