Gdx.files.local NullPointerException - PullRequest
       10

Gdx.files.local NullPointerException

0 голосов
/ 26 июня 2018

Я пытаюсь создать файл сохранения, но я получаю исключение NullPointerException при попытке вызвать метод "fileUserName". Может кто-нибудь, пожалуйста, объясните, почему я получаю эту ошибку и как ее исправить?

public class Register {
GridPane grid;

. , , .

public Pane getPane() {

    TextField text_name = new TextField();
    TextField text_password = new TextField();
    TextField text_reenterpassword = new TextField();
    Button button_ok = new Button("OK");


    button_ok.setOnAction(e -> {
        String userName=text_name.getText();
        String password=text_password.getText();
        String rePassword=text_reenterpassword.getText();
        DataSaving dataSave=new DataSaving(userName,password);

            if (! (new File("src/data/user/ "+userName).exists()))  {
                FileHandle fileUser= dataSave.fileUserName("src/data/user/"+userName);
                dataSave.saveUser(fileUser);
            }

            new LevelEstimation();

            stage.close();

    });     
    return grid;
  }}   

public class DataSaving {

String userName,password;
int userId;
public static String userPath;

public DataSaving(String username,String pass)
{
    this.userName=username;
    this.password=pass;
}

public static FileHandle fileUserName(String userName)
{
     return Gdx.files.local(userName+"/"+"loginData.json");
}

public void saveUser(FileHandle loginFile)  // saving the user name and password in a file
{
    User user=new User(userName,password);
    Json json=new Json();
    json.setOutputType(OutputType.json);    //to set quotation in json file to each string
    loginFile.writeString(json.prettyPrint(user), false);
}
}

Итак, я получаю сообщение об ошибке, когда метод "fileUserName" в классе "DataSaving" вызывается при нажатии кнопки "button_ok" внутри класса "Register"

Любая помощь будет оценена, спасибо.

...