save folios as objects in a file java












0















I am trying to do a program in which a user will be able to create folios and buy/sell stocks etc. I want to create a save button so the user will be able to save its current folio. The IPortofolioDb is an interface of the PortofolioDb where all the methods for the user data are implemented. I tried to do the follow but it doesnt work and i literally run out of ides. Can anyone help me ?



public class saveFolioListener implements ActionListener {
private Gui g;
private IPortfolioDb folios;

public saveFolioListener(Gui g, IPortfolioDb folios) {
this.g = g;
this.folios = folios;
}

@Override
public void actionPerformed(ActionEvent arg0) {

String fileName= "data.txt";
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(folios);
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("saved");

}

}


updated :



    java.io.NotSerializableException: java.util.concurrent.ScheduledThreadPoolExecutor
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
saved
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at saveFolioListener.actionPerformed(saveFolioListener.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)









share|improve this question

























  • "Doesn't work" is a much too imprecise error description. What is the error or output (edit the question to show it as properly formatted text)?

    – Michael Butscher
    Nov 22 '18 at 23:09











  • @MichaelButscher sorry i updated with the errors i have, there are a lot :(

    – Andreas
    Nov 22 '18 at 23:16











  • Classes to serialize must implement Serializable

    – Michael Butscher
    Nov 22 '18 at 23:18











  • @MichaelButscher did it, got new bunch of errors

    – Andreas
    Nov 22 '18 at 23:22











  • The object contains a ScheduledThreadPoolExecutor which can't be serialized. A quick solution would be transient but probably your database class (or the program as a whole) has design problems.

    – Michael Butscher
    Nov 22 '18 at 23:29


















0















I am trying to do a program in which a user will be able to create folios and buy/sell stocks etc. I want to create a save button so the user will be able to save its current folio. The IPortofolioDb is an interface of the PortofolioDb where all the methods for the user data are implemented. I tried to do the follow but it doesnt work and i literally run out of ides. Can anyone help me ?



public class saveFolioListener implements ActionListener {
private Gui g;
private IPortfolioDb folios;

public saveFolioListener(Gui g, IPortfolioDb folios) {
this.g = g;
this.folios = folios;
}

@Override
public void actionPerformed(ActionEvent arg0) {

String fileName= "data.txt";
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(folios);
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("saved");

}

}


updated :



    java.io.NotSerializableException: java.util.concurrent.ScheduledThreadPoolExecutor
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
saved
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at saveFolioListener.actionPerformed(saveFolioListener.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)









share|improve this question

























  • "Doesn't work" is a much too imprecise error description. What is the error or output (edit the question to show it as properly formatted text)?

    – Michael Butscher
    Nov 22 '18 at 23:09











  • @MichaelButscher sorry i updated with the errors i have, there are a lot :(

    – Andreas
    Nov 22 '18 at 23:16











  • Classes to serialize must implement Serializable

    – Michael Butscher
    Nov 22 '18 at 23:18











  • @MichaelButscher did it, got new bunch of errors

    – Andreas
    Nov 22 '18 at 23:22











  • The object contains a ScheduledThreadPoolExecutor which can't be serialized. A quick solution would be transient but probably your database class (or the program as a whole) has design problems.

    – Michael Butscher
    Nov 22 '18 at 23:29
















0












0








0








I am trying to do a program in which a user will be able to create folios and buy/sell stocks etc. I want to create a save button so the user will be able to save its current folio. The IPortofolioDb is an interface of the PortofolioDb where all the methods for the user data are implemented. I tried to do the follow but it doesnt work and i literally run out of ides. Can anyone help me ?



public class saveFolioListener implements ActionListener {
private Gui g;
private IPortfolioDb folios;

public saveFolioListener(Gui g, IPortfolioDb folios) {
this.g = g;
this.folios = folios;
}

@Override
public void actionPerformed(ActionEvent arg0) {

String fileName= "data.txt";
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(folios);
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("saved");

}

}


updated :



    java.io.NotSerializableException: java.util.concurrent.ScheduledThreadPoolExecutor
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
saved
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at saveFolioListener.actionPerformed(saveFolioListener.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)









share|improve this question
















I am trying to do a program in which a user will be able to create folios and buy/sell stocks etc. I want to create a save button so the user will be able to save its current folio. The IPortofolioDb is an interface of the PortofolioDb where all the methods for the user data are implemented. I tried to do the follow but it doesnt work and i literally run out of ides. Can anyone help me ?



public class saveFolioListener implements ActionListener {
private Gui g;
private IPortfolioDb folios;

public saveFolioListener(Gui g, IPortfolioDb folios) {
this.g = g;
this.folios = folios;
}

@Override
public void actionPerformed(ActionEvent arg0) {

String fileName= "data.txt";
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(folios);
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("saved");

}

}


updated :



    java.io.NotSerializableException: java.util.concurrent.ScheduledThreadPoolExecutor
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
saved
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at saveFolioListener.actionPerformed(saveFolioListener.java:28)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)






java file portfolio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 23:22







Andreas

















asked Nov 22 '18 at 22:59









AndreasAndreas

66




66













  • "Doesn't work" is a much too imprecise error description. What is the error or output (edit the question to show it as properly formatted text)?

    – Michael Butscher
    Nov 22 '18 at 23:09











  • @MichaelButscher sorry i updated with the errors i have, there are a lot :(

    – Andreas
    Nov 22 '18 at 23:16











  • Classes to serialize must implement Serializable

    – Michael Butscher
    Nov 22 '18 at 23:18











  • @MichaelButscher did it, got new bunch of errors

    – Andreas
    Nov 22 '18 at 23:22











  • The object contains a ScheduledThreadPoolExecutor which can't be serialized. A quick solution would be transient but probably your database class (or the program as a whole) has design problems.

    – Michael Butscher
    Nov 22 '18 at 23:29





















  • "Doesn't work" is a much too imprecise error description. What is the error or output (edit the question to show it as properly formatted text)?

    – Michael Butscher
    Nov 22 '18 at 23:09











  • @MichaelButscher sorry i updated with the errors i have, there are a lot :(

    – Andreas
    Nov 22 '18 at 23:16











  • Classes to serialize must implement Serializable

    – Michael Butscher
    Nov 22 '18 at 23:18











  • @MichaelButscher did it, got new bunch of errors

    – Andreas
    Nov 22 '18 at 23:22











  • The object contains a ScheduledThreadPoolExecutor which can't be serialized. A quick solution would be transient but probably your database class (or the program as a whole) has design problems.

    – Michael Butscher
    Nov 22 '18 at 23:29



















"Doesn't work" is a much too imprecise error description. What is the error or output (edit the question to show it as properly formatted text)?

– Michael Butscher
Nov 22 '18 at 23:09





"Doesn't work" is a much too imprecise error description. What is the error or output (edit the question to show it as properly formatted text)?

– Michael Butscher
Nov 22 '18 at 23:09













@MichaelButscher sorry i updated with the errors i have, there are a lot :(

– Andreas
Nov 22 '18 at 23:16





@MichaelButscher sorry i updated with the errors i have, there are a lot :(

– Andreas
Nov 22 '18 at 23:16













Classes to serialize must implement Serializable

– Michael Butscher
Nov 22 '18 at 23:18





Classes to serialize must implement Serializable

– Michael Butscher
Nov 22 '18 at 23:18













@MichaelButscher did it, got new bunch of errors

– Andreas
Nov 22 '18 at 23:22





@MichaelButscher did it, got new bunch of errors

– Andreas
Nov 22 '18 at 23:22













The object contains a ScheduledThreadPoolExecutor which can't be serialized. A quick solution would be transient but probably your database class (or the program as a whole) has design problems.

– Michael Butscher
Nov 22 '18 at 23:29







The object contains a ScheduledThreadPoolExecutor which can't be serialized. A quick solution would be transient but probably your database class (or the program as a whole) has design problems.

– Michael Butscher
Nov 22 '18 at 23:29














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438881%2fsave-folios-as-objects-in-a-file-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438881%2fsave-folios-as-objects-in-a-file-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy