ayuda!! Exception in thread "main" java.lang.NullPointerException
Publicado por Rocio (21 intervenciones) el 10/06/2022 00:27:07
Buenas noches.
Estoy trabajando en un juego con MVC. Lo estoy haciendo con vista en consola y me sale el error:
Exception in thread "main" java.lang.NullPointerException
at Vista.VistaConsola.menu(VistaConsola.java:32)
at Vista.VistaConsola.iniciar(VistaConsola.java:188)
at Controlador.ControladorJuego.<init>(ControladorJuego.java:53)
Les dejo mis clases:
Estoy trabajando en un juego con MVC. Lo estoy haciendo con vista en consola y me sale el error:
Exception in thread "main" java.lang.NullPointerException
at Vista.VistaConsola.menu(VistaConsola.java:32)
at Vista.VistaConsola.iniciar(VistaConsola.java:188)
at Controlador.ControladorJuego.<init>(ControladorJuego.java:53)
Les dejo mis clases:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package Modelo;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.awt.Color;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException;
import java.rmi.Remote;
import Cartas.Cartas;
import Cartas.Mazo;
import Cartas.Palos;
import Modelo.Jugador;
public class Juego extends ObservableRemoto implements IJuego{
public ArrayList<Jugador> jugadores = new ArrayList<>();
public ArrayList<Jugador> jugador
public Juego() {
jugadorActual = 0;
ronda = 1;
}
public void agregarJugador (String nombre) throws RemoteException {
jugadores.add(new Jugador(nombre));
notificarObservadores(2);
}
}
package Vista;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Scanner;
import Vista.ControlVista;
import Controlador.ControladorJuego;
import Modelo.Jugador;
public class VistaConsola implements ControlVista {
private static ControladorJuego miControl;
public void menu() throws RemoteException {
System.out.println("-------------------------");
System.out.println("- Configuración -");
System.out.println("-------------------------");
System.out.println("- M E N U -");
System.out.println("-------------------------");
System.out.println("- 1 - Agregar Jugador -");
System.out.println("- 2 - Mostrar Jugadores -");
System.out.println("- 3 - Iniciar Juego -");
System.out.println("-------------------------");
System.out.println(" ");
Scanner a = new Scanner(System.in);
int i = a.nextInt();
switch (i) {
case 1:
miControl.agregarJugador(nombreJugador());
break;
case 2:
miControl.mostrarJugadores();
break;
case 3:
miControl.jugando();
break;
}
}
public String nombreJugador()throws RemoteException {
String nom="";
System.out.println("Ingrese nombre de jugador ");
Scanner sc = new Scanner(System.in);
nom = sc.nextLine();
return nom;
}
public void mostrarJugadores() throws RemoteException {
ArrayList<Jugador> jugadores = miControl.getJugadores();
System.out.println(jugadores);
}
public void iniciar() throws RemoteException{
menu();
}
package Controlador;
import Cartas.Cartas;
import Modelo.IJuego;
import Modelo.Juego;
import Modelo.Jugador;
import Vista.ControlVista;
import Vista.VistaConsola;
import Vista.VistaGrafica;
import ar.edu.unlu.rmimvc.cliente.IControladorRemoto;
import ar.edu.unlu.rmimvc.observer.IObservableRemoto;
public class ControladorJuego implements IControladorRemoto ;
private IJuego miJuego;
private ControlVista miVista;
public ControladorJuego(ControlVista miVista) throws RemoteException {
this.miVista = miVista;
miVista.iniciar();
}
public void agregarJugador(String nombre) throws RemoteException {
miJuego.agregarJugador(nombre);
}
public String mostrarJugadores() throws RemoteException {
return miJuego.mostrarJugadores();
}
public void actualizar(IObservableRemoto modelo, Object queCambio) throws RemoteException{
int cambio = (int) queCambio;
switch (cambio) {
case 1:
break;
case 2:
System.out.println("Jugador agregado con exito");
break;
}
}
public interface ControlVista {
void menu() throws RemoteException;
}
Valora esta pregunta


0