[nbusers] java fx class loader

  • From: "handman" < >
  • To:
  • Subject: [nbusers] java fx class loader
  • Date: Fri, 27 Apr 2012 14:35:32 +0000

I was looking into porting some of my Labs data apps to java fx to utilize 
some its graphs and animation features.  I wrote a quick test program to 
connect to one of the data files utilizing the sqlitejdbc driver and ran into 
a snag. I can run the code fine from within netbeans, but when I try to build 
and then run executable jar file I get an " java.lang.CalssNotFoundException: 
org.sqlite.JDBC" error when it tries to execute the "Class.forName" command.  
I created a quick app utilizing swing and everything runs smoothly. I have 
included the sqlitejdbc jar file in the libraries.  Does anyone know what the 
problem could be?  Code is below.

Thanks


Code:
public class Main extends Application {


    
    final Button DBConnect = new Button("Connect");
    private boolean connected = false;
    final Label msg = new Label("Disconnected");
    
    private Connection conn;
    
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        DBConnect.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(connected)
                    disconnect();
                else
                    connect();
            }
        });
        
        VBox root = new VBox();
        root.setAlignment(Pos.CENTER);
        root.getChildren().addAll(DBConnect, msg);
        primaryStage.setScene(new Scene(root, 400, 70));
        primaryStage.show();
    }
    
    
    private void connect()
    {
        try
        {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:test.db");
            msg.setText("Connected");
            connected = true;
            DBConnect.setText("Disconnect");
        }
        catch(Exception e)
        {
            msg.setText(e.toString());
        }
    }
    
    private void disconnect()
    {        
        try
        {
            conn.close();
            msg.setText("Disconnected");
            connected = false;
            DBConnect.setText("Connect");
        }
        catch(Exception e)
        {
            msg.setText(e.toString());
        }
        
    }
    
    
}








[nbusers] java fx class loader

handman 04/27/2012

[nbusers] java fx class loader

handman 04/27/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close