Spinner.setadapter on a null object reference [closed]

0

The array of players is populated with data but gives error in method setadapter .

Spinner spinnerJogador1;

   ArrayList<JogadorModel> jogadores = jogadorRepository.SelecionarDisponiveis();

dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, jogadores);

        // Drop down layout style - list view with radio button
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);    
        // attaching data adapter to spinner
        spinnerJogador1.setAdapter(dataAdapter);
    
asked by anonymous 04.07.2017 / 11:57

1 answer

1

@UltraSenven You need to assign the spinnerJogador1 variable to the Spinner component you put in the view, try this:

su_view.xml

<Spinner
    android:id="@+id/id_do_seu_spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

SuaActivity.java

Spinner spinnerJogador1 = (Spinner) findViewById(R.id.id_do_seu_spinner);
    
05.07.2017 / 13:24