Я не уверен, знаком ли кто-нибудь с этим упражнением или ресурсом по программированию.Это мой рабочий источник. addressbook-level4
Я работаю над созданием функции аутентификации пользователя, в которой база данных пользователей хранится вместе в файле XML.Проблема в том, что он НЕ записывает / сохраняет созданных пользователей в XML, хотя файл базы данных создается по правильному пути к файлу.Точнее говоря, произошла ошибка при преобразовании данных в XML и записи их в файл.
Я понятия не имею, что мне здесь не хватает, кто-нибудь достаточно любезный, чтобы посмотреть, пожалуйста, дайте мне знать, если кому-то нужночто нибудь еще.Большое спасибо за время и терпение.Для меня это много значит.
Трассировка стека:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8863)
at javafx.controls/com.sun.javafx.scene.control.behavior.TextFieldBehavior.fire(TextFieldBehavior.java:184)
at javafx.controls/com.sun.javafx.scene.control.behavior.TextInputControlBehavior.lambda$keyMapping$62(TextInputControlBehavior.java:330)
at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4083)
at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1600(Scene.java:4029)
at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2146)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2620)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1784)
... 47 more
Caused by: java.lang.AssertionError: Unexpected exception 1 counts of IllegalAnnotationExceptions
at seedu.address.storage.XmlFileStorage.saveUsersToFile(XmlFileStorage.java:46)
at seedu.address.storage.XmlUserDatabaseStorage.saveUserDatabase(XmlUserDatabaseStorage.java:74)
at seedu.address.storage.StorageManager.saveUserDatabase(StorageManager.java:124)
at seedu.address.storage.StorageManager.saveUserDatabase(StorageManager.java:118)
at seedu.address.storage.StorageManager.handleUserDatabaseChangedEvent(StorageManager.java:138)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:95)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:154)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:80)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:76)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:119)
at com.google.common.eventbus.EventBus.post(EventBus.java:215)
at seedu.address.commons.core.EventsCenter.post(EventsCenter.java:41)
at seedu.address.commons.core.ComponentManager.raise(ComponentManager.java:26)
at seedu.address.model.ModelManager.indicateUserDatabaseChanged(ModelManager.java:134)
at seedu.address.model.ModelManager.addUser(ModelManager.java:159)
at seedu.address.logic.commands.CreateUserCommand.execute(CreateUserCommand.java:43)
at seedu.address.logic.LogicManager.executeNoLoginCommands(LogicManager.java:71)
at seedu.address.logic.LogicManager.execute(LogicManager.java:42)
at seedu.address.ui.CommandBox.handleCommandEntered(CommandBox.java:107)
... 58 more
Метод saveUsersToFile:
public static void saveUsersToFile(Path file, XmlSerializableUserDatabase userDatabase)
throws FileNotFoundException {
try {
XmlUtil.saveDataToFile(file, userDatabase);
} catch (JAXBException e) {
throw new AssertionError("Unexpected exception " + e.getMessage());
}
Сериализуемая база данных пользователей:
@XmlRootElement(name = "users")
public class XmlSerializableUserDatabase {
@XmlElement
private List<XmlAdaptedUser> users;
/**
* Creates an empty XmlSerializableUserDatabase
* This empty constructor is required for marshalling.
*/
public XmlSerializableUserDatabase() {
users = new ArrayList<>();
}
/**
* Conversion
*/
public XmlSerializableUserDatabase(ReadOnlyUserDatabase src) {
this();
users.addAll(src.getUsersList().stream().map(XmlAdaptedUser::new).collect(Collectors.toList()));
}
/**
* Converts this addressbook into the model's {@code AddressBook} object.
*
* @throws IllegalValueException if there were any data constraints violated or duplicates in the
* {@code XmlAdaptedPerson} or {@code XmlAdaptedTag}.
*/
public UserDatabase toModelType() throws IllegalValueException {
UserDatabase userDatabase = new UserDatabase();
for (XmlAdaptedUser user : users) {
userDatabase.addUser(user.toModelType());
}
return userDatabase;
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof XmlSerializableUserDatabase)) {
return false;
}
return users.equals(((XmlSerializableUserDatabase) other).users);
}
}