Android spinner.setAdapter Generates Resources$NotFoundException


November 2018


418 time


Greetings I am new to Android development, long time programmer (Ada, Objective-C, C++, C#) and new to Java. My code generates an exception when applying the ArrayAdapter to a spinner, namely: spinner.setAdapter(adapter); This causes my Android app to crash. Needless to say, the spinner is not displayed.

I've searched StackOverflow and have not found any really definitive answers - yet. The code (below) is practically verbatim from the Android Developers Guide.

public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {

public View onCreateView(
        LayoutInflater inflater, 
        ViewGroup container,
        Bundle savedInstanceState) 
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get the spinner id.
    Spinner spinner = (Spinner)rootView.findViewById(;

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(),

    // Specify the layout to use when the list of choices appears

    // Apply the adapter to the spinner

    return rootView;


The array data for the spinner is located in a resource file: res\values\mission_types.xml, it is verbatim from the example.

<?xml version="1.0" encoding="utf-8"?>
<string-array name="mission_type_array">

When the code executes, spinner.setAdapter(adapter) generates an exception.

LogCat (below) indicates:

Resource ID #0x7f090006 type #0x12 is not valid
E/AndroidRuntime(6373):  at android.content.res.Resources.loadXmlResourceParser

In the Debugger, I set a breakpoint and step through the code. In the Variables window, I can click on the spinner and get info in the detail pane: android.widget.Spinner{b2dce690 VFED..C. ......I. 0,0-0,0 #7f090006 app:id/spinner1}. The Hex number #7f09 corresponds to the LogCat message above indicating "not valid".

In the Debugger Variables window, I can also drill-down into the spinner and adapter to verify the data from the resource file has been loaded.

So why, is the spinner "not valid" and what can be done to correct this?

Thank you in advance for your help. I hope to return the favor in the future. Cheers,

1 answers


Третий параметр createFromResoruceявляется раскладка идентификатор, используемый для создания представления, а не идентификатор блесны. Ты можешь использоватьandroid.R.layout.simple_spinner_item