Problema com java.lang.NullPointerException

jan 20, 2017 9:38:49 PM estacionecar.FormTelaPrincipalController clicouUsuario
GRAVE: null
javafx.fxml.LoadException:
file:/C:/Users/Filomena%20C%20G/Documents/NetBeansProjects/EstacioneCar/dist/run1718458723/EstacioneCar.jar!/estacionecar/formUsuario.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at estacionecar.formUsuario.start(formUsuario.java:26)
at estacionecar.FormTelaPrincipalController.clicouUsuario(FormTelaPrincipalController.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException
at estacionecar.formUsuarioController.carregarTableViewUsuario(formUsuarioController.java:107)
at estacionecar.formUsuarioController.initialize(formUsuarioController.java:93)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
… 67 more

Posta o Arquivo formUsuarioController.java tudo indica que o erro está la.
Linha 93

/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package estacionecar;

import java.net.URL;
import java.sql.Connection;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import estacionecar.model.dao.UsuarioDAO;
import estacionecar.model.database.Database;
import estacionecar.model.database.DatabaseFactory;
import estacionecar.model.domain.Usuario;
import javafx.event.ActionEvent;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;

/**
*

  • @author brunoGaldino
    */

public class formUsuarioController implements Initializable {

@FXML
private Button btnSalvar, btnCancelar, btnEditar, btnSair, btnExcluir;
private TextField txtNome, txtSenha, txtLogin;
private TableView<Usuario> tbUsuario;
@FXML
private TableColumn<Usuario, String> tbcolNome;
@FXML
private TableColumn<Usuario, String> tbcolLogin;
@FXML
private CheckBox cbAdministrador, cbCliente, cbCaixa, cbRelatorio, cbPreco, cbFinanceiro;

@FXML
private TableColumn<Usuario, Boolean> tbcolAdministrador;

@FXML
private List<Usuario> listUsuario;
private ObservableList<Usuario> observableListUsuario;

//Atributos para manipulação do banco de dados.

private final Database database = DatabaseFactory.getDatabase("postgresql");
private final Connection connection = database.conectar();
private final UsuarioDAO  usuarioDAO = new UsuarioDAO();
           

@FXML
private void clicouSalvar(ActionEvent event){
    
}

@FXML
private void clicouCancelar(ActionEvent event){
    
}

@FXML
private void clicouEditar(ActionEvent event){
    
}

@FXML
private void clicouSair(ActionEvent event){
    formUsuario.myStage.close();
    
}
@FXML
private void clicouExcluir(ActionEvent event){
    
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    usuarioDAO.setConnection(connection);
    carregarTableViewUsuario();
    
    // Listen acionado diante de quaisquer alterações na seleção de itens do TableView
    tbUsuario.getSelectionModel().selectedItemProperty().addListener(
            (observable, oldValue, newValue) -> selecionarItemTableViewUsuario(newValue));       
}
public void carregarTableViewUsuario() {
    tbcolNome.setCellValueFactory(new PropertyValueFactory<>("nome"));
    tbcolLogin.setCellValueFactory(new PropertyValueFactory<>("login"));
    //tbcolAdministrador.setCellValueFactory(new PropertyValueFactory<>("administrador"));

    listUsuario = usuarioDAO.listar();

    observableListUsuario = FXCollections.observableArrayList(listUsuario);
    tbUsuario.setItems(observableListUsuario);  
}
  
public void selecionarItemTableViewUsuario(Usuario usuario){
    if(usuario != null) {
        txtNome.setText(usuario.getNome());
        txtLogin.setText(usuario.getLogin());
        txtSenha.setText(usuario.getSenha());
        //cbAdministrador.setSelected(usuario.getAdministrador());
        //cbCaixa.setSelected(usuario.getPcaixa());
        //cbCliente.setSelected(usuario.getPcliente());
        //cbRelatorio.setSelected(usuario.getPrelatorio());
        //cbFinanceiro.setSelected(usuario.getPfinanceiro());
        //cbPreco.setSelected(usuario.getPpreco());
    } else {
        txtNome.setText("");
        txtLogin.setText("");
        txtSenha.setText("");
        //cbAdministrador.setSelected(false);
        //cbCaixa.setSelected(false);
        //cbCliente.setSelected(false);
        //cbRelatorio.setSelected(false);
        //cbPreco.setSelected(false);
        //cbFinanceiro.setSelected(false);           

    }

}    

}

Estava achando que era esse campos boolean que estava dando problema mais comentei eles e o problema persistiu

Bruno estou tentando te ajudar de cabeça, mas assim passando o olho no código, e por desencargo de consciência . Experimente o seguinte:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package estacionecar;

import java.net.URL;
import java.sql.Connection;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import estacionecar.model.dao.UsuarioDAO;
import estacionecar.model.database.Database;
import estacionecar.model.database.DatabaseFactory;
import estacionecar.model.domain.Usuario;
import javafx.event.ActionEvent;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;

/**
*
* @author brunoGaldino
*/

public class formUsuarioController implements Initializable {

@FXML
private Button btnSalvar, btnCancelar, btnEditar, btnSair, btnExcluir;

@FXML
private TextField txtNome, txtSenha, txtLogin;

@FXML
private TableView<Usuario> tbUsuario;

@FXML
private TableColumn<Usuario, String> tbcolNome;

@FXML
private TableColumn<Usuario, String> tbcolLogin;

@FXML
private CheckBox cbAdministrador, cbCliente, cbCaixa, cbRelatorio, cbPreco, cbFinanceiro;

@FXML
private TableColumn<Usuario, Boolean> tbcolAdministrador;

@FXML
private List<Usuario> listUsuario;

@FXML
private ObservableList<Usuario> observableListUsuario;

//Atributos para manipulação do banco de dados.

private final Database database = DatabaseFactory.getDatabase("postgresql");

private final Connection connection = database.conectar();

private final UsuarioDAO  usuarioDAO = new UsuarioDAO();


@FXML
private void clicouSalvar(ActionEvent event){

}

@FXML
private void clicouCancelar(ActionEvent event){

}

@FXML
private void clicouEditar(ActionEvent event){

}

@FXML
private void clicouSair(ActionEvent event){
    formUsuario.myStage.close();

}
@FXML
private void clicouExcluir(ActionEvent event){

}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    usuarioDAO.setConnection(connection);
    carregarTableViewUsuario();

    // Listen acionado diante de quaisquer alterações na seleção de itens do TableView
    tbUsuario.getSelectionModel().selectedItemProperty().addListener(
            (observable, oldValue, newValue) -> selecionarItemTableViewUsuario(newValue));       
}
public void carregarTableViewUsuario() {
    tbcolNome.setCellValueFactory(new PropertyValueFactory<>("nome"));
    tbcolLogin.setCellValueFactory(new PropertyValueFactory<>("login"));
    //tbcolAdministrador.setCellValueFactory(new PropertyValueFactory<>("administrador"));

    listUsuario = usuarioDAO.listar();

    observableListUsuario = FXCollections.observableArrayList(listUsuario);
    tbUsuario.setItems(observableListUsuario);  
}
  
public void selecionarItemTableViewUsuario(Usuario usuario){
    if(usuario != null) {
        txtNome.setText(usuario.getNome());
        txtLogin.setText(usuario.getLogin());
        txtSenha.setText(usuario.getSenha());
        //cbAdministrador.setSelected(usuario.getAdministrador());
        //cbCaixa.setSelected(usuario.getPcaixa());
        //cbCliente.setSelected(usuario.getPcliente());
        //cbRelatorio.setSelected(usuario.getPrelatorio());
        //cbFinanceiro.setSelected(usuario.getPfinanceiro());
        //cbPreco.setSelected(usuario.getPpreco());
    } else {
        txtNome.setText("");
        txtLogin.setText("");
        txtSenha.setText("");
        //cbAdministrador.setSelected(false);
        //cbCaixa.setSelected(false);
        //cbCliente.setSelected(false);
        //cbRelatorio.setSelected(false);
        //cbPreco.setSelected(false);
        //cbFinanceiro.setSelected(false);           

    }

}
}

Repare que apenas declarei o @FXML emcima de cada linha de componentes.
Veja se há mudança na Exception.

Desconfio que alguns componentes não estão sendo criados devido a falta desta anotação e te trazendo esse Null Pointer . Logo no método Initialize.

1 curtida

Frmichetti eh o problema nao eh este :sweat: tentando encontrar alguma solução

1 curtida

Consegui resolver alterando o metodo como estava chamando a tela de usuarios

        public void clicouUsuario() throws IOException, Exception {
        new formUsuario().start(new Stage());
    }
1 curtida

Certo. Ainda bem.:grin:

1 curtida

vlw pela força!!!

1 curtida