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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:06:23+00:00 2026-06-09T11:06:23+00:00

How do I fix this error? I can’t find anything to help me! Code

  • 0

How do I fix this error? I can’t find anything to help me! Code snippets would be appreciated!

The reason the adapter for sp2 is set within the onItemSelected for sp1 is because I want the output for sp2 to be dependent on the selection made in sp1.

logcat:

    08-05 16:36:24.856: D/dalvikvm(6606): GC_EXTERNAL_ALLOC freed 81K, 43% free 3119K/5379K, external 2770K/2773K, paused 28ms
08-05 16:36:25.707: D/AndroidRuntime(6606): Shutting down VM
08-05 16:36:25.707: W/dalvikvm(6606): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
08-05 16:36:25.707: E/AndroidRuntime(6606): FATAL EXCEPTION: main
08-05 16:36:25.707: E/AndroidRuntime(6606): java.lang.NullPointerException
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:291)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.widget.AbsSpinner.setAdapter(AbsSpinner.java:113)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at com.madonk.louisiana.festivals.Region$1.onItemSelected(Region.java:107)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:877)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.widget.AdapterView.access$200(AdapterView.java:42)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:843)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.os.Handler.handleCallback(Handler.java:587)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.os.Looper.loop(Looper.java:130)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at android.app.ActivityThread.main(ActivityThread.java:3821)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at java.lang.reflect.Method.invokeNative(Native Method)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at java.lang.reflect.Method.invoke(Method.java:507)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-05 16:36:25.707: E/AndroidRuntime(6606):     at dalvik.system.NativeStart.main(Native Method)

Here is the offending code:

sp2.setAdapter(sc_cit_adp);

.java:

package com.madonk.louisiana.festivals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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

/**
 * @author madonk
 *
 */
public class Region extends Activity {

Spinner sp1,sp2,sp3;
ArrayAdapter<String> reg_adp,sw_cit_adp,sc_cit_adp,sw_lake_charles_adp,sw_iowa_adp,sc_lafayette_adp,sc_gueydan_adp;
List<String> regions,sw_cities,sc_cities,sw_lake_charles,sw_iowa,sc_lafayette,sc_gueydan;

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

    String[] regionsArray = getResources().getStringArray(R.array.regions_array);
    regions = new ArrayList<String>(Arrays.asList(regionsArray));

    String[] swcitiesArray = getResources().getStringArray(R.array.southwest_cities_array);
    sw_cities = new ArrayList<String>(Arrays.asList(swcitiesArray));

    String[] swiowaArray = getResources().getStringArray(R.array.sw_iowa_array);
    sw_iowa = new ArrayList<String>(Arrays.asList(swiowaArray));

    String[] swlakecharlesArray = getResources().getStringArray(R.array.sw_lake_charles_array);
    sw_lake_charles = new ArrayList<String>(Arrays.asList(swlakecharlesArray));

    String[] sclafayetteArray = getResources().getStringArray(R.array.sc_lafayette_array);
    sc_lafayette = new ArrayList<String>(Arrays.asList(sclafayetteArray));

    String[] scgueydanArray = getResources().getStringArray(R.array.sc_gueydan_array);
    sc_gueydan = new ArrayList<String>(Arrays.asList(scgueydanArray));

    sp1= (Spinner) findViewById(R.id.regions_spinner);
    sp2= (Spinner) findViewById(R.id.city_spinner);
    sp3= (Spinner) findViewById(R.id.festival_spinner);

    reg_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,regions);
    reg_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    sp1.setAdapter(reg_adp);

    sw_cit_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,sw_cities);
    sw_cit_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    sw_lake_charles_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,sw_lake_charles);
    sw_lake_charles_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    sw_iowa_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,sw_iowa);
    sw_iowa_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    sc_cit_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,sc_cities);
    sc_cit_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    sc_lafayette_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,sc_lafayette);
    sc_lafayette_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    sc_gueydan_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,sc_gueydan);
    sc_gueydan_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);


    sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {


                 String reg_select = (sp1.getSelectedItem().toString());
                 if (reg_select.contentEquals("Southwest")){
                     sp2.setAdapter(sw_cit_adp); 
                     sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

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

                             String sw_cit_select = (sp2.getSelectedItem().toString());
                             if (sw_cit_select.contentEquals("Lake Charles")){
                                 sp3.setAdapter(sw_lake_charles_adp); }

                             else if (sw_cit_select.contentEquals("Iowa")){
                                 sp3.setAdapter(sw_iowa_adp); }


                            ;}

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

                            };});}

                 else  if (reg_select.contentEquals("South Central")){
                     sp2.setAdapter(sc_cit_adp); 
                     sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

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

                             String sc_cit_select = (sp2.getSelectedItem().toString());
                             if (sc_cit_select.contentEquals("Lafayette")){
                                 sp3.setAdapter(sc_lafayette_adp); }

                             else if (sc_cit_select.contentEquals("Gueydan")){
                                 sp3.setAdapter(sc_gueydan_adp); }


                            ;}

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

                            };});}

                 }



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

    }
});}}
  • 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-09T11:06:25+00:00Added an answer on June 9, 2026 at 11:06 am

    That’s because you are trying to access sw_cit_adp from inside of an Anonymous inner class. These classes only like when the data members they access are final
    Make sure you have something like

    final ArrayAdapter sw_cit_adp = new ArrayAdapter();
    

    where your variable is final.

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

Sidebar

Related Questions

Can anyone help me? I can't fix this error when building an ios app
Can anyone help me to fix this error on getPointerCount() , getX() , and
How can I fix this error without redundant code? public Comparison2(decimal number1, decimal number2)
Can anyone help me fix this script? I get this error: Msg 4104, Level
How can I fix this error, and install thin or other gems? $ sudo
I'm getting this error in the log.... What can I do to fix this?
I can't fix this problem on my listview template: i have the error as
What causes this error, how can I fix it? Detailed Error Information Module IIS
how can I fix this error ? Target of assignment must be a reference
Can anyone help me on how this error came up There is already an

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.