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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:59:22+00:00 2026-05-28T04:59:22+00:00

Alright, so I’m new to Android programming, so far my experience has been quite

  • 0

Alright, so I’m new to Android programming, so far my experience has been quite interesting and challenging. But I fear I have now encountered the first problem I’m not able to overcome on my own.

Simply put, all I want to do is have 2 Spinners:
1 for country selection
1 for province/state selection

What I want to accomplish is that when the user selects his/her country the province/state Spinner is updated with the correct adapter. Currently I’m only using 2 country for testing purposes.

When I launch the Activity, I get an exception and my app crashes.

Here’s my code, any pointers would be appreciated !

    public class ManageAccountActivity extends Activity {

    final ArrayAdapter<CharSequence> adapterSexe = ArrayAdapter.createFromResource(ManageAccountActivity.this, R.array.sex_array_fr, android.R.layout.simple_spinner_item);
    final ArrayAdapter<CharSequence> adapterProvince = ArrayAdapter.createFromResource(ManageAccountActivity.this, R.array.province_array_fr, android.R.layout.simple_spinner_item);
    final ArrayAdapter<CharSequence> adapterStates = ArrayAdapter.createFromResource(ManageAccountActivity.this, R.array.state_array_fr, android.R.layout.simple_spinner_item);
    final ArrayAdapter<CharSequence> adapterCountry = ArrayAdapter.createFromResource(ManageAccountActivity.this, R.array.country_array_fr, android.R.layout.simple_spinner_item);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.account_management);

        Spinner spinSexe = (Spinner) findViewById(R.id.spin_sex);
        Spinner spinProvince = (Spinner) findViewById(R.id.spin_province);
        Spinner spinCountry = (Spinner) findViewById(R.id.spin_country);

        adapterSexe.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        adapterProvince.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        adapterStates.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spinSexe.setAdapter(adapterSexe);
        spinProvince.setAdapter(adapterProvince);
        spinCountry.setAdapter(adapterCountry);

        spinCountry.setOnItemSelectedListener(new CountryOnItemSelectedListener());   
    }   

    public class CountryOnItemSelectedListener implements OnItemSelectedListener {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            setContentView(R.layout.account_management);
            Spinner spinProvince = (Spinner) view.findViewById(R.id.spin_province);

            if (parent.getItemAtPosition(pos).toString().equals("Canada")) {
                spinProvince.setAdapter(adapterProvince);
            } else {
                spinProvince.setAdapter(adapterStates);
            }
        }

        public void onNothingSelected(AdapterView parent) {
          // Do nothing.
        }
    }
}

Here’s the LogCat message I’m getting.

01-10 20:41:01.024: E/AndroidRuntime(1275):
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{gggolf.android.minutegolf/gggolf.android.minutegolf.ManageAccountActivity}:
java.lang.NullPointerException

  • 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-28T04:59:23+00:00Added an answer on May 28, 2026 at 4:59 am

    You cannot instantiate your ArrayAdapter directly on class attribut, because createFromResource() use Context, and it’s not exists at this time, do it in onCreate() methode instead.

    In addition, you get spin province wrong in your listener, you can’t call findViewById on view local variable, because it’s not your layout, but an inflate of android.R.layout.simple_spinner_item

    The good way:

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            Spinner spinProvince = (Spinner) findViewById(R.id.spin_province);
    
            if (parent.getItemAtPosition(pos).toString().equals("Canada")) {
                spinProvince.setAdapter(adapterProvince);
            } else {
                spinProvince.setAdapter(adapterStates);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright so i have been working on this Dynamic load of a spinner from
Alright, I have a table of tasks this table has a foreign key which
Alright I'm pretty new to programming and stuff and I'm now trying to code
Alright, I'm extremely new to programming so odds are this is a really easy
Alright, currently I have my SWF hitting a php file that will go and
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright, i have read many different views on how to do this with no

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.