我正在学习Java并在netbeans中试验Javafx.
我在这里运行sqlite教程:http://www.tutorialspoint.com/sqlite/sqlite_java.htm
当设置为单独文件时,它当然可以正常工作.
我在测试项目"testDB"中进行设置,出于某种原因,当我启动类时,类本身被识别,但是main()没有运行.
这是testdb文件本身:
/*
* 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 sqlitetest;
import java.sql.*;
/**
*
*/
public class testDB {
public static void main(String args[]) {
//THESE STEPS ARE ON NOT RUNNING (compiles without errors)
System.out.println("testing");
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
public void makeStuff(){
}
}
Run Code Online (Sandbox Code Playgroud)
/*
* 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 sqlitetest;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
*/
public class Sqlitetest extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
testDB test = new testDB();
test.makeStuff();
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为你在构造函数和main方法之间感到困惑.
在testdb,改变:
public static void main(String args[]) {
Run Code Online (Sandbox Code Playgroud)
至
public testdb() {
Run Code Online (Sandbox Code Playgroud)
或者,调用testdb.main(args)(或使用其他一些参数)Sqlitetest.main.
| 归档时间: |
|
| 查看次数: |
469 次 |
| 最近记录: |