Writing to file is flawless -- reading works but returns nothing.

This was a homework assignment for my 2nd Java course, and I'm not posting here for the easy way out I DO want to learn this, I'm just stuck.
Program simply -- Create/write a file with a vector inside of it, which contains an object. Allow the user to insert as many objects as they want into the vector. Once the file is created, display the contents.
Simple enough, I managed to create what I thought would work flawlessly, but when I try to read the contents of the file, the program exits code 0, without displaying the object variables I asked of it. Here is the attached code (I've left out the Person class simply to save space, but it it contained two variables (name and yob), as well as proper setters and getters):
public class homework1 {
    static Scanner keyb = new Scanner(System.in);
    public static void main(String[] args) {
        Person x = new Person();
        //I prefer flagging here
        Vector<Person> allPersons = new Vector<Person>();
        int flag = 1;
        System.out.println("Please type 'add' to add a Person to the list.");
        System.out.println("Please type 'view' to view the current list.");
        String s = keyb.next();
        if (s.equalsIgnoreCase("add")) {
            System.out.println();
            while (flag == 1) {
                System.out.print("Enter person's name: ");
                String u = keyb.next();
                x.setName(u);
                System.out.print("Enter person's year of birth: ");
                int t = keyb.nextInt();
                x.setYob(t);
                allPersons.addElement(x);
                try {
                    FileOutputStream f =
                        new FileOutputStream("C:/Documents and Settings/Constantine/Desktop/test.dat");
                    ObjectOutputStream b = new ObjectOutputStream(f);
                    b.writeObject(allPersons);
                    f.close();
                } catch (IOException e) {
                    e.toString();
                System.out.print("Add another student? (y/n): ");
                String v = keyb.next();
                if (v.equalsIgnoreCase("y")) {
                    System.out.print("Enter new student details");
                    System.out.println();
                } else {
                    System.out.println("Finished updating student list.");
                    flag--;
            if (s.equalsIgnoreCase("view")) {
                System.out.println();
                try {
                    FileInputStream f =
                        new FileInputStream("C:/Documents and Settings/Constantine/Desktop/test.dat");
                    ObjectInputStream b = new ObjectInputStream(f);
                    try{
                    allPersons = (Vector<Person>)b.readObject();
                        for(int i=0; i<allPersons.size(); i++) {
                            System.out.print(allPersons.get(i).getName());
                            System.out.print(allPersons.get(i).getYob());
                    } catch (ClassNotFoundException e) {
                        e.toString();}
                        f.close();
                        } catch (IOException e) {
                            e.toString();
        }If someone can point my in the right direction as to why my vector's object's variables aren't being displayed I'd appreciate it!
/cheers

OK, I added the printStackTrace() and got this returned, maybe it will mean more to you than I can understand haha
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: Person
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1309)
     at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1634)
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
     at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1908)
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
     at homework1.main(homework1.java:107)
Caused by: java.io.NotSerializableException: Person
     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
     at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
     at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:391)
     at java.util.Vector.writeObject(Vector.java:1018)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:585)
     at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
     at homework1.main(homework1.java:68)

Similar Messages

  • I updated Firefox and now it will not open at all. The hourglass shows that it's working but then nothing. I went to add/remove and removed mozilla and reinstalled it and still the same thing. It worked fine before I updated.

    I updated Firefox and now it will not open at all. The hourglass shows that it's working but then nothing. I went to add/remove and removed mozilla and reinstalled it and still the same thing. It worked fine before I updated. Now I can't even remove the program at all. Why is this happening?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    Create a new profile as a test to check if your current profile is causing the problems.
    See "Basic Troubleshooting: Make a new profile":
    *https://support.mozilla.com/kb/Basic+Troubleshooting#w_8-make-a-new-profile
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins" in case there are still problems.
    If that new profile works then you can transfer some files from the old profile to that new profile, but be careful not to copy corrupted files.
    See:
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • War file created in Eclipse works, but fails when created by Ant

    Hi,
    I am having trouble getting my flex war file to work when I create it using Ant, even though the same war works fine when I create it from my Eclipse Export War function. This is a critical problem and any ideas or suggestions would be greatly appreciated.
    I have a working installation of LCDS running under JBoss 4.0.5 (in a CENTOS (Red Hat) environment). I have implemented a datatier in Java to interact with my PostgreSQL 8.x database. The Java code, plus the necessary flex jars and xml files and some mxml test programs, are all in an Eclipse J2EE project that I created from the flex samples.war file. It all works fine when I use Eclipse to create a WAR from the project and deploy it in JBoss. My problem is this: When I create a WAR piece by piece using Ant, then deploy it to JBoss, that WAR does not work. The error I get is this:
    javax.servlet.ServletException: Invalid Configuration: see previous failures. flex.webtier.util.ServiceUtil.setupFlexService(ServiceUtil.java:55) flex.webtier.server.j2ee.MxmlServlet.init(MxmlServlet.java:57), etc.
    When I look at the log I see this problem:
    "You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.",
    but that error is in the server log even when I use the good WAR file.
    I have compared the two wars but cannot find any substantial difference between them.
    Thanks in advance!

    Have you tried enabling debug level logging and removing the category filters in services-config.xml? It should show all the destinations being created, and if any are failing. To get the maximum level of log detail, something like this should work:
    ><logging>
    >
    > <target class="flex.messaging.log.ConsoleTarget" level="Debug">
    >
    > <properties>
    >
    > <prefix>[Flex] </prefix>
    >
    > <includeDate>false</includeDate>
    >
    > <includeTime>false</includeTime>
    >
    > <includeLevel>false</includeLevel>
    >
    > <includeCategory>false</includeCategory>
    >
    > </properties>
    >
    > </target>
    >
    > </logging>
    Have a check that your remoting destinations are shown starting correctly for both WAR files, and see if there are any messages in the log that might be relevant.

  • HT4101 The camera connector suddenly stopped importing photos like it used to.  Now it will import 1 or 2 photos and then **** off and revert to the desk top.  The Sd reader works, but I miss the quicker option of the cord and connected.

    I have two Canon Elph cameras.  They both were easy to use with my IPad until two months ago when it suddenly stopped working on either camera/cord. It would check the new photos displayed on the screen and then shut down, import one or two, and go back to the desktop. Frustrating.  The SD reader works, though. Is the camera connected faulty?

    Are you running a Managed or a Referenced Library?
    A Managed Library, is the default setting, and iPhoto copies files into the iPhoto Library when Importing. The files are then stored in the Library package
    A Referenced Library is when iPhoto is NOT copying the files into the iPhoto Library when importing because you made a change at iPhoto -> Preferences -> Advanced. (You unchecked the option to copy files into the Library on import) The files are then stored where ever you put them and not in the Library package. In this scenario you are responsible for the File Management. 

  • I purchased a new iMac with latest iLife suite, however, IMovie will not read my videos.  I deleted a 3iVX file that was not working but nothing happens now. Help

    I just purchased a new iMac with the latest iLife suite. As part of the migration process in setting up the new machine the 3Ivx video codec was brought onto the new machine as well as my old movies.  When I tried opening the movies iMovie crashed and told me it had a problem with the 3IVX video codec, in doing some research I found that the 3IVX video codec created a problem so I deleted it and downloaded Perian 123.  The Perian 123 works well with Quicktime but iMove does not now see my old movies.  At this point I cannot open any of my movies.  Can anyone help?  Thanks

    There also might be a more updated, compatible 3ivx codec you can install, or just try re-installing a newly downloaded version of of the same old codec: http://www.3ivx.com/download/macos.html
    Otherwise download and install MPEG Streamclip: http://www.squared5.com/svideo/mpeg-streamclip-mac.html
    In iMovie hold down CTRL and click on the clips that don't open. Choose Reveal in Finder. Convert those files by dragging them into the window of converter program, and save as Apple Intermediate Codec (AIC). That format is native to iMovie and will work perfectly.

  • Have file name with date working but appending the time to file name can't get a result

    DECLARE @dt AS VARCHAR(26)
    SELECT @dt = REPLACE(CONVERT(VARCHAR(26),getDate(),110),'-','-'
    Have this appended to a filename like: log_01-15-2015.  Don't know what to add to SQL code to get the get the time and append time in hours, min, sec. like:  log_01-15-2015_10:01:33  
    DECLARE @dt AS VARCHAR(50)
    SELECT @dt = REPLACE(CONVERT(VARCHAR,CURRENT_TIMESTAMP,110),'-','-') +'_'+ CONVERT(VARCHAR,CURRENT_TIMESTAMP,108)
    EXEC master.dbo.sp_configure 'show advanced options',1
    RECONFIGURE WITH OVERRIDE
    EXEC master.dbo.sp_configure 'xp_cmdshell',1
    RECONFIGURE WITH OVERRIDE
    SET @bcpCommand = 'bcp "SELECT * FROM ##Temp ORDER BY barcode" queryout "C:\TEMP\Log\ContainerHistory_Log_' + @dt +'" -c -T'
    EXEC master..xp_cmdshell @bcpCommand
    I am trying to append to the file created with the date a time stamp but when appending the time part for the filename results aren't creating the file.  If it's just doing the date part then it is working. Any idea what is wrong? 

    Since you added ":" to the file name, the file name is not valid. You can change ":" to "-".
    DECLARE @dt AS VARCHAR(50)
    SELECT @dt = CONVERT(VARCHAR,CURRENT_TIMESTAMP,110) +'_'+ REPLACE(CONVERT(VARCHAR,CURRENT_TIMESTAMP,108), ':', '-')
    SELECT @dt
    A Fan of SSIS, SSRS and SSAS

  • USB card reader working, but not showing up in removable media... why?

    For some reason lately, my USB mounts, but doesn't show up in the Finder left-hand area with the other removable media, such as DVDs. I have to access it via My Computer, where it does show up. And I have to eject it in Disk Utility.
    It does show up normally in iPhoto.
    Any idea why this might happen?
    Thanks,
    doug

    Welcome! ...I would try Apple's 'Troubleshooting Assistant' first : )
    http://www.apple.com/support/ipod/five_rs/

  • I cannot change the font size on firefox. Works on other browsers but not on FF and writing is too small. Ctl+ works but its a nuisance each time

    Have windows 7 but even on Vista the fonts on FF are too small and I cannot change the size.

    You can use one of these extensions to adjust the default font size and page zoom on web pages:
    * Default FullZoom Level - https://addons.mozilla.org/firefox/addon/6965
    * NoSquint - https://addons.mozilla.org/firefox/addon/2592
    * http://kb.mozillazine.org/Zoom_text_of_web_pages

  • File with appropriate disk space, but with nothing on it!

    Hi!
    I have this friend whom accordingly recorded some her stuff. Everything was fine then somebody did something with it (and can't explain what exactly) and now it's still as big as before (like 700 Mo of disk space) but when you open it, well there's nothing!
    Do you know what probably happened? Or if there is a software which ccan help retrieve the lost data (if indeed this seems the case)?
    Thanks a lot and sorry for the bad english, good night to you all!
    Miranda.
    Message was edited by: Miydras

    ctrl-click the file, open the media folder, drop the contents into a new GB project.

  • I can't open Gmail in Firefox. Used to work but now nothing.

    It seems I am getting the same as others. Google works fine. Gmail works in Google but not in Firefox. Was OK but now get the error message; "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
    Have tried all the suggestions but naught. Have the latest Firefox.
    Help!!!!

    Hello,
    Many site issues can be caused by corrupt cookies or cache. In order to try to fix these problems, the first step is to clear both cookies and the cache.
    Note: ''This will temporarily log you out of all sites you're logged in to.''
    To clear cache and cookies do the following:
    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
    #Now click the ''Clear now'' button.
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Problem in French translation while writing a file on application server

    I am writing some text symbols to a file on application server using Transfer statement. But for some french characters the data is not transleted correctly. I have maintained the french translation for these text symbols.

    Hi,
    Make sure you use the correct encoding while writing your file.
    Regards.

  • Ctl-T nor the File-Open Tab are working any more. Did you kill this?

    I am a heavy user of the Ctl-T function, which opens a new tab on my existing Firefox screen. It is no longer working. Also, when I select File - New Tab, that doesn't open a new tab either.
    The File - New Window option works, but I don't want to have multiple Firefoxes open on my system.
    I've used this feature forever, and in the last couple of weeks (didn't notice the exact time), it stopped working. Did you change something?

    Try uninstalling the Ask toolbar and it should work again. There is a compatibility issue with the Ask toolbar and the current version of Firefox.

  • My CD/DVD drive reads CDs but not DVDs

    Hi All
    I have a TSSTcorp CDDVDW TS-L633M DVD drive in my laptop and after about 6 months of use, the drive stopped reading/writing DVDs. It still reads CDs fine and occasionally will read a DVD (completely unprovoked and without warning...!) but is very temperamental and will randomly just stop reading a DVD. Often, the drive will eject and give an error message telling me to insert a disc. I'm not sure what to do.
    I'm running Windows Vista 32-bit. I have tried running the Microsoft Fixit application, which recognises that the drive is failing to read DVDs but offers nothing more helpful than that and doesn't fix anything (despite its name...). I have been reading through a number of different forums and have found a range of advice: replacing the drive, uninstalling and reinstalling the drivers or editing the registry. What should I be doing to fix this problem? Naturally, I'd prefer not to have to replace the drive itself, but if that's the only way...
    Thanks in advance!
    Mangi
    This question was solved.
    View Solution.

    The registry thing only works if the drive is completely AWOL from the system so that it does not appear as a drive in "My Computer"....not your issue. The DVD and the CD use different lasers and it is not uncommon for one to go bad and the other not. You can check the function of the DVD by trying to boot from a bootable DVD. If you cannot the drive is bad and needs to be replaced. If it works sometimes and not others it could just need a good cleaning with a DVD lens cleaner.

  • Can't view PDF files using Acrobat Reader X

    We made many PDF files available on our Web site. In the past few weeks we noticed that users who were using Acrobat Reader X and Internet Explorer 8 or 9 were not able to view some PDF files. Basically, when they clicked a link to display a PDF file, the screen would be cleared and the status bar showing "Loading ...KB/...K/B" would be displayed. The status bar would move a bit and then got stuck. The PDF file would never be displayed. Sometimes, my users could click the Back button to go back the previous Web page and sometimes they had to close or kill the IE window. Small PDF files seemed to be fine. I was able to repeat this problem on PCs running Windows XP and Windows 7. I also tested clicking the same PDF files with PCs installed with Acrobat Reader 9 and I was not able to cause the problem to occur, so I am pretty sure that this problem is related to Acrobat Reader X. I also noticed that if I unchecked the "Display PDF in browser"  option in Acrobat Reader X so that PDF files would not be displayed inside the Internet Explorer window, I would be able to view all PDF files without any problems.
    I also did an experiment by resaving many PDF files using Acrobat Pro (Reduce File Size...) to be compatible with Acrobat 8 or above. I was able to open these PDF files using Acrobat Reader X but when I used a PC with Acrobat 9, it would get stuck instead. Most of my PDF files were created a long time ago and we usually made it compatible with Acrobat 5 or above.
    I saw that some people reported some problems with Acrobat Reader X but I did not see a solution except uninstalling Acrobat Reader X and installing an old version of Acrobat Reader instead. Anyone has any ideas why this is happening and how to fix this problem?
    RJ

    Sounds like you got the trial of Acrobat. Go to add/remove programs, get rid of it, the download the free Reader from http://get.adobe.com/reader/

  • Since the latest software update, every third or so time I turn it on, my sounds settings are changed and I cannot listen to anything-music, YouTube, nothing. I can sometimes change something and it will work, but right now nothing is working. Anyone else

    Since latest software update, my sound settings are changing sometimes when I turn on and cannot hear anything. All controls are useless and cannot be activated. After changing several things, I have been able to make it work, but today nothing is working. Anyone else experience this  and have any ideas?

    Try reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

Maybe you are looking for

  • Opening/Closing Queue Reference By Name

    I'm curious if opening and closing a queue reference to put information onto the queue, using the queue name -> obtain queue -> enqueue -> release queue(Non Force) is problematic.  I thought i saw a thread a long time ago that opening/closing a refer

  • Proble while creating new Data Connection for the Webservice

    Hai All, when creating a new Data Conneciotn for the Webservice in the interactive form i got the following errror Cannot choose this operation: - there is no associated SOAP Binding edit -> new Data Connection -> WSDL -> i entered the wsdl url -> i

  • Satellite Pro 4360 - Booting from SSD via Cardbus (PCMCIA) possible?

    Hi all, I have an old SP 4360. Does anyone know if a BIOS upgrade to 2.70 will allow me booting off a SSD inserted into the Cardbus pc card slot? Right know the Bios only recognizes DVD, HDD and FLOPPY as boot devices. Second issue: I have confllicti

  • Extension to batch change link relativity

    I'm trying to find the DW CS3 extension that batch converts all the links from Document to Site Root or the other way around. I can't remember what it was called. Anyone know? I need it to change the links in an HTML email created in DW CS3. Thanks i

  • Online backup fail on a file

    i am trying to backup and got the initial backup just fine. subsequent backups, I have one file 102 MB that continues to fail and don't know why. how can I determine why a backup file fails?