-1
The purpose of the code is to pass a arraylist of Sessao for the builders sala2D and 3D(in the constructor, the name of the arraylistof Sessao is "Session"). But after some tests it is found that the builders receive a arraylist null. How to solve this problem?.
private void cadastrarActionPerformed(java.awt.event.ActionEvent evt) {
try{
int check=0;
int valid=0;
Sessao sessao;
ArrayList<Sessao> session= new ArrayList();
if(quatorze.isSelected()){
sessao= new Sessao("14h",Integer.parseInt(capacidade.getText()));
session.add(sessao);
}
if(dezesseis.isSelected()){
sessao=new Sessao("16h",Integer.parseInt(capacidade.getText()));
session.add(sessao);
}
if(dezoito.isSelected()){
sessao=new Sessao("18h",Integer.parseInt(capacidade.getText()));
session.add(sessao);
}
if(salaBox.getSelectedIndex()==0){
Sala novaSala2D= new Sala2D(Integer.parseInt(numero.getText()),Integer.parseInt(capacidade.getText()),session,filmes.getSelectedItem().toString());
Cinema.salas.add(novaSala2D);
check=0;
}
else if(salaBox.getSelectedIndex()==1){
Sala novaSala3D= new Sala3D(Integer.parseInt(numero.getText()),Integer.parseInt(capacidade.getText()),novo,filmes.getSelectedItem().toString());
Cinema.salas.add(novaSala3D);
check=1;
/*for (Sessao sessoe : novaSala3D.getSessoes()) {
System.out.println(novaSala3D.getSessoes().);
}*/
}
if(check==0){
JOptionPane.showMessageDialog(null,"Sala 2D Cadastrada com sucesso!");
clear();
}
else{
JOptionPane.showMessageDialog(null,"Sala 3D Cadastrada com sucesso!");
clear();
}
}
catch(NumberFormatException exception){
JOptionPane.showMessageDialog(null, "Por favor, cadastre um filme na tela anterior no registro de filmes antes de vir aqui!");
}
catch(NullPointerException exception){//Se o usuário não insere um valor numérico, uma excessão é gerada.
JOptionPane.showMessageDialog(null,"Por favor, insira um valor numérico inteiro nos campos de texto!");
}
}
At the startup of the variable
novaSala3Dyou are using the variablenovowhich is not located in any of your code. That’s why?– Bruno Costa