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

  • Home
  • SEARCH
  • 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 8195063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:00:33+00:00 2026-06-07T05:00:33+00:00

I am trying to make adapters for spinners, however I get an NullPointerException on

  • 0

I am trying to make adapters for spinners, however I get an NullPointerException on answertime.setAdapter(adapter); Why is this? My arrays are in the strings.xml where they should be?
Here is the full code.

package lijap.app.starcraft2counters;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class Settings extends Activity implements OnItemSelectedListener {
Spinner answertime;
Spinner gametime;
Spinner missesallowed;

String[] answerseconds = { "Unlimited", "1 second", "2 seconds",
        "3 seconds", "4 seconds", "5 seconds" };

String[] gameminutes = { "Unlimited", "1 minute", "2 minutes", "3 minutes",
        "4 minutes", "5 minutes" };

String[] numberofmisses = { "Unlimited", "5", "10", "15", "20", "25" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);

    ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.AnswerSeconds, R.layout.custom_spinner_list);
    adapter.setDropDownViewResource(R.layout.custom_spinner);
    answertime.setAdapter(adapter);

    ArrayAdapter adapter2 = ArrayAdapter.createFromResource(this, R.array.GameMinutes, R.layout.custom_spinner_list);
    adapter.setDropDownViewResource(R.layout.custom_spinner);
    gametime.setAdapter(adapter);

    ArrayAdapter adapter3 = ArrayAdapter.createFromResource(this, R.array.NumberOfMisses, R.layout.custom_spinner_list);
    adapter.setDropDownViewResource(R.layout.custom_spinner);
    missesallowed.setAdapter(adapter);


    answertime = (Spinner) findViewById(R.id.s_answertime);
    answertime.setAdapter(adapter);
    answertime.setOnItemSelectedListener(this);


    missesallowed = (Spinner) findViewById(R.id.s_mistakenumber);
    missesallowed.setAdapter(adapter2);
    missesallowed.setOnItemSelectedListener(this);

    gametime = (Spinner) findViewById(R.id.s_gametime);
    gametime.setAdapter(adapter3);
    gametime.setOnItemSelectedListener(this);
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    // TODO Auto-generated method stub

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

}

Any help is appreciated- Lijap

  • 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-07T05:00:36+00:00Added an answer on June 7, 2026 at 5:00 am

    you never initialize answertime, gametime, or missesallowed. you need to do something like this,

    answertime = findViewById(R.id.<the id for this spinner>);
    gametime = findViewById(R.id.<the id for this spinner>);
    missesallowed = findViewById(R.id.<the id for this spinner>);
    

    before you call setAdapter() on them.

    also, here’s another problem,

    ArrayAdapter adapter2 = ArrayAdapter.createFromResource(this, R.array.GameMinutes, R.layout.custom_spinner_list);
    adapter.setDropDownViewResource(R.layout.custom_spinner);
    gametime.setAdapter(adapter);
    

    notice that you construct something into the reference adapter2, then you modify adapter, and set adapter as the adapter for the spinner. is that what you want?

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

Sidebar

Related Questions

I'm trying to put some custom list adapters into their own classes to make
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
I am trying to make a form with 2 spinners, I want the content
I am trying to make a form with 2 spinners, I want the content
I am trying to make a form with 2 spinners, I want the content
I am trying to make a form with 2 spinners, I want the content
I am trying to make a form with 2 spinners, I want the content
I am trying to make a form with 2 spinners, I want the content
I am trying to make a form with 2 spinners, I want the content

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.