Error in serialization when file name is dynamic
Hello there,
I am utilizing serialization functionality of Java to Save the work done using the application that I have developed. When the user goes to File -> Save, the application calls the following function:
public void save()
try{
System.out.println("before FOS");
FileOutputStream f_out = new FileOutputStream("*save.data*");
System.out.println("after FOS");
ObjectOutputStream out = new ObjectOutputStream (f_out);
System.out.println("after OOS");
out.writeObject(*myPanel*);
//myPanel is an instance of JPanel which contains all the sketches done by the user.
out.close();
f_out.close();
System.out.println("after writeObject");
catch(Exception e)
System.out.println("Exception in Save function");
This particular code runs fine but the problem is that the name of the serialized file is hard coded which is, "save.data" as highlighted in bold in the above code.
So I added the JFileChooser component to enable the user to type in the file name that he/she wants. The following is the amended code:
public void save()
JFileChooser chooserSave = new JFileChooser();
chooserSave.setCurrentDirectory(new File ("."));
returnVal2 = chooserSave.showSaveDialog(myPanel);
File fileName = chooserSave.getSelectedFile();
System.out.println("filename : " + fileName);
if(returnVal2 == JFileChooser.APPROVE_OPTION)
try{
System.out.println("before FOS");
FileOutputStream f_out = new FileOutputStream(fileName);
System.out.println("after FOS");
ObjectOutputStream out = new ObjectOutputStream (f_out);
System.out.println("after OOS");
out.writeObject(myPanel);
out.close();
f_out.close();
System.out.println("after writeObject");
catch(Exception e)
System.out.println("Exception in Save function");
With the amended code however, the programs throws exception after bold line which means writeObject method could not be performed.
Could anyone kindly advice what could be wrong? I have made almost all the possible amendments to the best of my knowledge but to no avail.
Thank you very much.
Note: This question has been posted earlier in java-forums.org @ http://www.java-forums.org/advanced-java/20147-serialization.html
You shouldn't Serialize swing components - draw the sketches to images or save them as their own objects and read them back in to populate the JPanel.
The reason you are suddenly getting the Exception is because the JFileChooser is referenced within the JPanel while you are saving it - and that particular partof the JFileChooser is not Serializable.
As was said before, you shouldn't Serialize swing components (the API specifies that swing serialized objects may not be compatible with future releases).
Similar Messages
-
When I try importing a CD following message comes up: error occurred whilst converting file " name of fist song on CD" You do not have the privilege to make changes. Any ideas? thanks John.
Read the part about changing permissions on the iTunes folder in: https://discussions.apple.com/message/11583914
-
Error message "A duplicate file name was specified"
Every time I open iTunes or attempt to make a purchase, I get the error message "A duplicate file name was specificed. There was an error in the iTunes Stores. Please try again later."
It started when I tried to download a book a few days ago.
I do not have any plugins installed, so there are none to remove/disable. I'm running the most recent version of iTunes (11.0.5) for Windows 7 (64-bit). I tried clearing the iTunes cache to no avail.Try and unchecking Manually manage music and videos on the summary page in iTunes. To get there, just go to ____'s iPod, scroll down, and it should be there. You can then check any other boxes (or uncheck) that you think might help you. That box might have automatically checked itself after the update. Also, make sure you have the latest version of iTunes by going to the apple in the top left hand corner, and clicking software update.
-
I get the message “Server not responding” whenever trying to add files to my web site via DW. The following message appears: "An FTP error occurred - cannot put [file name.htm]. Dreamweaver encountered an internal data error. Please try the operation again."
I called the hosting service provider, and they said they were able to upload a 20 mb document with no problem. I was also able to upload a document using Filezilla.
Therefore, the problem must be with DW.
When I go to Manage Sites and choose my site and get to the Test Connection button, the test is successful, which further confuses the issue.
Any guidance would be greatly appreciated.Does this help?
http://forums.adobe.com/thread/861606
Also check the log:
http://forums.adobe.com/thread/937231
It is possible it is a host issue but because they use a higher level account to test that they do not see the error. -
I am trying to sync my iPod nano 5th generation to my computer and when i go to add music through iTunes i get the following message:
The iPod "X's iPod" cannot be synced. A duplicate file name was specified. Any ideas how to fix this?
On my computer (iMac) while in iTunes it is showing that the music is indeed on my iPod, but when i eject the iPod there is nothing there.I have a 27" iMac with the latest version of iTunes. I tried restoring my iPod and even removing and re-installing iTunes. What eventually worked for me was plugging into my PC and restoring/reformatting it to work with my PC. I don't know why it wouldn't work with my iMac, but now it seems to be working.
-
Problem:obtaing file name using Dynamic configuration of file adapter
hi all
I am using Dynamic configuration for getting file name.
I am getting Dynamic configuration in SXMB_MONI containg file name, but payload is empty unlike file i am sending.Hi All,
Basically my requirement to get Filename in idoc segments in order to validate the posting at month end.
Its an File to idoc scenario- GL Posting.
Please check attached UDF and it gives error. Kindly help. Thanks -
I have recently purchased a new desktop under WIN 7 as well as Adobe Creative Suite CS6.
My first internal hard disk is 2 TB, the second one installed is from my old PC, 250 GB.
I am getting this error when trying to save a file over an existing file using the “Save” command.
The message is wrong, because the file name IS valid.
This error is persistent.
This error does not occur when doing the same action on my second internal hard disk.
This error happens on files larger than about 1MB in weight.
What happens is that the original file over which I try to do the ”Save” command gets corrupted and lost.
If I don't use the “Save as” command to save my work under a different name, my work is lost.
The same problem occurs with both PS CS6 versions, 64 Bit and 32 Bit.
I am very disappointed and annoyed with this happening.
Any idea what is going on here?ok ...
I think I have resolved this.
I forgot to mention that I have Sugarsync over that file structure.
However, I do not know if Sugarsync has anything to do with the error.
I copied the whole folder structure under a newly created folder, and I am no longer getting the error.
Thanks
Milan -
Trouble when file name has spaces
In Windows XP's Windows Explorer, when I double click a .pdf file to open it the Adobe Reader comes up and then sometimes puts up a pop-up saying "There was an error opening this document. This file cannot be found". I have to click OK several times to get the pop-up to go down.
After some internet investigation I discovered if the file's path name has spaces then Adobe breaks the path into pieces at the spaces and interprets it as several file names. The advice I found on the internet was to have the launching application put double quotes around the file name.
The trouble is, in my case the launching application is Windows XP, and I don't know how to instruct it to add the double quotes.I WANT THE PASSWORD
SAYS ANOTHER ACCOUNT WITH THE SAME ADDRESS
I WANT THE PASSWORD -
Upgraded computer from XP Prof 32-Bit to Windows 7 Ultimate 64-Bit (Upgrade package, performed Custom Install).
Attempt to install iTunes 10.4.1 for 64-Bit. Receiving the following error/problem:
The Folder Path "File Name on my external drive" contains an invalid character
I click ok and then get this:
The Installer encountered errors before iTunes could be configured. Errors occurred during installation. Your system could not be modified, Please run the installer again, or click Finish to exit.
Any fixes for this?Sorry, one of us is not managing to be clear enough.
Does the message read The Folder Path "File Name on my external drive" contains an invalid character or perhaps The Folder Path "<some path name here>" contains an invalid character?
If so, then the problem might be just what it says it is with the path name in question... Either way if you list the path given in the error message in a reply to this thread it might provide a clue for anyone tying to help with the problem.
You could try downloading the installer to C:\iTunesSetup.exe in case that helps.
tt2 -
Receiver File Name assign dynamically
Hi friends,
In our scenario, receiver file name is assigned to dynamically. Example Inventory_Current date. Inventory is static, but CurrentDate is changed on runtime.
I was tried to Variable substitution method and UDF method. In this type dynamic value is mapped to target structure, so Receiver payload shows the dynamic value in output file. But we don't need that dynamic value. So, in variable substitution method and UDF method is not achived to my requirement.
Please any one help me how to change file name at runtime (receiver communication channel). If using any module program pls forward to me.
Thanks & Regards
VijayHi,
if we want to get the Output file name as One of the Field value from Payload and Current dase with it means,
1) Write one UDF & map Like this
Name(giri)-----UDFCurrent Date----MT_Target
2) Check the ASMA Option in Receiver Adapter Aloneu2026..
3)No need to check the ASMA Option in the Sender side
UDF Code:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File" , "FileName");
String Outputfile = conf.put(key,a);
return Outputfile;
Regards
Seshagiri -
Compiler error - bad command or file name
I have downloaded JDK 1.4 beta from this site and have
ammended the path commands in my Autoexec file. I use
the DOS edit to type my programs and save the files with
a .java extension. When I type javac Convertion.java for
example all I get is Bad command or file name.
Any assistance will be appreciated.either you haven't rebooted your machine or you have set the PATH correctly - first reboot, then double check autoexec.bat
-
Sender file Error - Detailed log on file name
Hi,
With sender File configuration the file name is given as pattern and for some reason i get the error "Conversion of file content to XML failed at position 0". I understand that as per FCC definition I have only 5 fields as my input strucure but the file has more than that...now the question is i want to find out which file (out of 100s) is having this issue as the name of the file is not logged in Comm monitoring. any help/insight on this please?Hi.
Have you had chance to check this parameter "additionalLastFields"? . According documentation
http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/frameset.htm
If the inbound structure has more fields than specified in the configuration then the XML outbound structure is created as follows:
○ ignore
Outbound structure only contains the fields in the inbound structure
○ error
Conversion is terminated due to the incomplete inbound structure. An error message is displayed.
Regards -
Target file name using Dynamic Configuration
Hi,
Currently we have requirement Idoc to File interface.In this scenario if one field exists infile then we have to check and we need to create update directory and if it is not exist then we should create one more directory and upload files over there there files should create with timestamp. Since,File system using Sql database so we have used JDBC lookup to check that particaluar field and if it exists we are passing update to UDF if it is not then we are passing constant Create to that. If we use Adapter Specific Message Attributes then in reciever side file Communication Channel addtimestap will it consider or do we have to write anything in Udf it self? Could anybody explain on this?Please provide some sample udf .
Thanks ,
Aparna.
Edited by: aparna_karnam on Dec 24, 2011 11:44 AM
Edited by: aparna_karnam on Dec 24, 2011 11:52 AMHi,
I have added little changes to the code you have written, to meet your expectations
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
conf.put(key,"/sap-dev/" +a);
DynamicConfiguration conf1 = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
string filename=conf1.get(key1);
final String DATE_FORMAT_NOW = "dd-MM-yyyy_HH-mm-ss";
String s;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT_NOW);
java.util.Calendar cal = java.util.Calendar.getInstance();
s=sdf.format(cal.getTime());
filename=a+" "+"User_"+s+".txt";
conf1.put(key1,filename);
return " ";
So if value of input variable "a" is "update" then the target directory will be "/sap-dev/update" and the file formed will have name "update User_26-12-2011_01-20-50.txt", of course the date and time values will change depending on server settings. I just showed a sample. one more point, the directory will not be created, you have to create the directories before you run the scenario, only the final directory will be decided depending on value of variable "a". In case you wanna create new directory if directory is not pre-existing then try ticking on "Create Target Directory" option under "file access parameters" in communication channel. (I have never used this option u can have a try. )
Now coming to your queries
1. But whether file type txt automatically it will take or do we have to give in udf it self ?
ans) You have to put the value in UDF as I have done in code.
2. how it will consider timestamp ?
ans) This has been generated in UDF itself.
3. how i can give file extension .txt?
ans) same as ans 1
4. And also in Receiver Communication Channel under Adapter Specific Message attributes we have option of file type how it works?
ans) File type determines is the file you are going to write is of type "text" or "binary". From "Processing Parameters" tab you can select this from drop down menu in communication channel or you can set it through ASMA properties in similar manner as you have done for file name and directory name. For more details refer to http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm
http://help.sap.com/saphelp_nwpi71/helpdata/en/44/6830e67f2a6d12e10000000a1553f6/content.htm
Finally few more points I would like to add
1) you have not mentioned the operating system of the server where file is going to form. In case its UNIX/LINUX you are not allowed to use space in the filename. you can consult these links before you decide on file name and directory name in the UDF mentioned above
http://www.med.nyu.edu/rcr/rcr/nyu_vms/unixfileanddirectorynames.htm (UNIX)
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions (WINDOWS)
2) you can alter the string "DATE_FORMAT_NOW" as per your requirement so that the timestamp appears in the way you want. I have just showed a sample.
3) Plesae do not forget to tick on the options "Use Adapter-Specific Message Attributes indicator", "Fail If Adapter-Specific Message Attributes Missing", indicators "File Name" and "Directory" under "Define Adapter-Specific Message Attributes." in receiver communication channel.
Hope this solves your problem.
Wish my dear forum members and users of SDN
Merry Christmas and Happy new year (in advance)
Regards
Anupam
N.B:- I initially forgot to add the ".txt" part to the file name. I made necessary corrections in code now. -
Error when file name with accent passed to GetFileDate()
Hi,
When i pass a file or a file that belongs to a path that has one of its folders names containing an accented character to GetFileDate(), i get a Library function error (return value == -1). For example all files within the folder 'Eéprom' return an error. Can anyone please offer some help on how i resolve this issue?
Thank you!
(LabWindowsCVI 9.0 / Windows 2000 / CVIRTE2009)
Solved!
Go to Solution.Hello sinnas!
After seeing your last post, I determined that the problem is actually in your BAT script. The dir /s /b /a-D \"%s\\*.*\" > \"%s\"\n command is not interpreting the accents correctly. You can make a simple test in a command prompt window to determine that.
In order to fix the problem you would have to set the code page of the command prompt running your BAT script accordingly.
Here are some community forum posts that address the exact issue you are experiencing:
http://stackoverflow.com/questions/7584423/problem-running-bat-cmd-file-with-accented-characters-in-...
http://stackoverflow.com/questions/1427796/batch-file-encoding
I hope this helps! -
Mail will not print, pages will not print . . . pages / mail quits unexpectedly while using the BJPDELocalizedString2 plugin. Tryed in Word for Mac. . .Error message; no pages found / filename This all happened when I unstalled brother P-touch.
Restart the computer in safe mode. Certain caches maintained by the system will be rebuilt.
Safe mode is much slower to start up than normal. The next normal startup may also be somewhat slow.
When the login screen appears, restart as usual (not in safe mode) and test. There's no need to log in while in safe mode.
Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, ask for instructions.
Maybe you are looking for
-
Can someone help me with an answer?
I have made a number of movies in iMovie as PAL then projected and burned them in iDVD as both PAL and NTSC so I have one master of each. The guy who is doing the copies for me has a dvd player and TV monitor that tells you if the movie is PAL or NTS
-
PDF not attaching to Outlook using Adobe Reader
When clicking the Mail icon on the tool bar in adobe reader to attach the PDF to an email, adobe reader freezes and the document does not attach. It does work if Outlook 2013 is closed but if Outlook 2013 is open adobe reader just freezes for a minut
-
Indesign and Illustrator CS6 crash upon opening. Photoshop is fine.
Hi, Everytime I launch CS6 indesign and illustrator i keep getting the classic "indesign quit unexpectedly..." message. I have already run the Adobe Application Manager and updated everything and uninstalled, reinstalled both items again and yes I ha
-
Tried to trash a large amount of files the count down is now in minuses. No files are locked. Trash it not helping
-
Hi, This is my code: begin for l_rec in ( select item_name from item_t where table_name = p_table_name order by display_seq loop if ( i = 1 ) then l_st