Al intentar crear un Spinner
con su adaptador y datos ya dentro creado me da un error de NullPointerException
, y no se donde se da dado que todo esta creado.
public class PartidaActivity extends AppCompatActivity {
private Button bAyuda;
private Button bTirar;
private ImageView dado;
private ImageView dado2;
private SoundPool sp;
private int sonidoDado=0;
private TextView nombreJugador;
private int turno;
private String valor,valorRecibido;
private Spinner spinnerValores;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pantalla_partida);
bAyuda = (Button) findViewById(R.id.botonAyudaPartida);
bTirar = (Button) findViewById(R.id.botonTirar);
dado = (ImageView) findViewById(R.id.Dado);
dado2 = (ImageView) findViewById(R.id.Dado2);
nombreJugador = (TextView) findViewById(R.id.nombreJugador);
spinnerValores = (Spinner) findViewById(R.id.eleccionTirada);
ArrayList<Valor> listaValores = new ArrayList<Valor>();
listaValores.add(new Valor(1,"Kiriki"));
listaValores.add(new Valor(2,"Ladrillo"));
listaValores.add(new Valor(3,"Pareja"));
listaValores.add(new Valor(4,"10"));
listaValores.add(new Valor(5,"9"));
listaValores.add(new Valor(6,"7"));
listaValores.add(new Valor(7,"6"));
listaValores.add(new Valor(8,"5"));
listaValores.add(new Valor(9,"4"));
ArrayAdapter<Valor> adaptador = new ArrayAdapter<Valor>(this,android.R.layout.simple_spinner_item,listaValores);
adaptador.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerValores.setAdapter(adaptador);
Pongo ahora lo que me dice el error.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.alex.proyecto, PID: 16525
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alex.proyecto/com.example.alex.proyecto.PartidaActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
at com.example.alex.proyecto.PartidaActivity.onCreate(PartidaActivity.java:66)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)