0
NetBeansを6ヶ月使用してこのプログラムを開発していますが、このような問題は一度もありません。 org.apache.commonsライブラリを追加すると(私はオンラインサーバから時間を得るために必要でした)、プログラムを実行すると、すべてがうまくいくことがあります。メインメソッドのクラスは次のとおりです。NTPUDPClientからの日時の取得に失敗する場合があります
package samplefx.ctrl;
import java.io.IOException;
import java.net.InetAddress;
import java.sql.Date;
import java.text.ParseException;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.commons.net.ntp.NTPUDPClient;
import org.apache.commons.net.ntp.TimeInfo;
public class Optilight extends Application {
public static EntityManagerFactory emf;
EntityManager em;
@Override
public void start(Stage primaryStage) throws IOException, ParseException {
emf = Persistence.createEntityManagerFactory("SampleFXPU");
String TIME_SERVER = "time-a.nist.gov";
NTPUDPClient timeClient = new NTPUDPClient();
InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
TimeInfo timeInfo = timeClient.getTime(inetAddress);
long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();
Date time = new Date(returnTime);
Access access = new Access();
String fix = "XC193283R";
String var = access.Y();
Date start = Date.valueOf("2016-08-23");
Date end = Date.valueOf("2016-08-31");
Boolean j = false;
if (start.before(time) && time.before(end)) {
j = true;
}
boolean i = false;
if (fix.equals(var)) {
i = true;
}
if (!j || !i) {
System.exit(0);
}
// load main form in to VBox (Root)
BorderPane mainPane = (BorderPane) FXMLLoader.load(getClass().getResource("/samplefx/view/Login.fxml"));
// add main form into the scene
Scene scene = new Scene(mainPane);
//primaryStage.setTitle("Optilight 2.2.1");
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.UNDECORATED);
//primaryStage.setMaximized(true); // make the main form fit to the screen
primaryStage.show();
primaryStage.setOnCloseRequest(e -> {
emf.close();
Platform.exit();
System.exit(0);
});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
問題は、サーバーへのリクエストがタイムアウトに陥ることが考えられます。プログラムを段階的にデバッグして、問題を特定してください。 – Blobonat
さらに、開始メソッドをよりプライベートなメソッドに分割すると、各関数をハングアップする場所を見るために "ステップオーバー"できるので、デバッグがより簡単になります。あなたのコードはより保守性にもなります。 – byxor
タイムアウトを短く設定すると問題が解決しますか? –