當我嘗試運行我的java fxml應用程序時,netbeans出現錯誤。運行Java FXML程序時出錯
這裏是我得到的錯誤:
產生的原因:在apnc7dsimulator.UIController.handleStart(UIController.java:4 2)apnc7dsimulator.UIController.handleNew(UIController顯示java.lang.NullPointerException。的java:37)在apnc7dsimulator.UIController.initialize(UIController.java:31)在javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)... 17更
它出現的誤差被始發從我的控制器。這裏是我的代碼:
public class UIController implements Initializable {
@FXML
private TextArea screen;
@FXML
private TextField commandLine;
private Login login;
@Override
public void initialize(URL location, ResourceBundle resources) {
handleNew();
}
public void handleNew(){
screen.clear();
commandLine.clear();
handleStart();
}
public void handleStart(){
login.loginSys(screen);
}}
代碼控制器引用是這樣的:
public class Login implements PrintToScreen{
@Override
public void print(String text, TextArea screen) {
screen.appendText(text);
}
@Override
public String read(TextArea screen) {
Scanner scanner = new Scanner(System.in);
String readString = scanner.nextLine();
while(readString != null){
print(readString,screen);
if(scanner.hasNextLine()){
readString = scanner.nextLine();
}
else{
readString = null;
}
}
return readString;
}
public void loginSys (TextArea screen)
{
String user = "...";
String pass = "...";
print("Please Enter Username:",screen);
user = read(screen);
print("Please Enter Password:",screen);
pass = read(screen);
print("Check Credentials... Please Wait.",screen);
}}
我敢肯定,這是一個簡單的錯誤,我正在做或某種約定,我不能正常以下,但這讓我難住了一段時間。 任何幫助將是偉大的。
謝謝,這似乎已經解決了,不能相信我錯過了那。 –