Results 1 to 6 of 6
- 01-16-2013, 07:15 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 14
- Rep Power
- 0
FileNotFoundException when attempting to save android game
When I click the button to save my android game, I get a FileNotFoundException
I cant understand why as the exact same code worked in my previous (non - android) version. Thanks a million in advance for any help 
Java Code:public void saveGame(Player user) { FileOutputStream saveStream; ObjectOutputStream savePlayerObject = null; String destinationFile = user.getName() + ".txt"; try { saveStream = new FileOutputStream(destinationFile); savePlayerObject = new ObjectOutputStream(saveStream); savePlayerObject.writeObject(user); }//end of try; catch(FileNotFoundException ex) { Toast toast = Toast.makeText(this, "Save Failed", Toast.LENGTH_LONG); toast.show(); }//end of catch statement; catch(IOException ex) { Toast toast = Toast.makeText(this, "Save Failed", Toast.LENGTH_LONG); toast.show(); }//end of catch statement; finally { try { if(savePlayerObject !=null) { savePlayerObject.flush(); savePlayerObject.close(); Toast toast = Toast.makeText(this, "Thank-You For Playing, See You Soon", Toast.LENGTH_LONG); toast.show(); System.exit(0); }//end of if-statement; }//end of try statement; catch(IOException ex) { Toast toast = Toast.makeText(this, "Save Failed", Toast.LENGTH_LONG); toast.show(); }//end of catch statement; }//end of finally statement; }//end of method;
- 01-16-2013, 07:24 PM #2
Re: FileNotFoundException when attempting to save android game
If you were originally running this code on a Windows system, and now you are trying to use the same code on the Android platform, the location of the File you are trying to reach would have changed, right? Is the file on the SD card? If it is you can use the following call to get the root of the SD Card:
Java Code:File f = Environment.getExternalStorageDirectory();
Last edited by sehudson; 01-16-2013 at 07:36 PM.
- 01-16-2013, 07:33 PM #3
Member
- Join Date
- Sep 2012
- Posts
- 14
- Rep Power
- 0
Re: FileNotFoundException when attempting to save android game
Sorry I should have said, I am just running the code on an android simulator in my windows laptop
- 01-16-2013, 07:38 PM #4
Re: FileNotFoundException when attempting to save android game
I believe there is a tool in the Android SDK called mksdcard that you have to use to create an SD Card image for your emulator to use. Check out the Android forum here.
- 01-16-2013, 08:00 PM #5
Member
- Join Date
- Sep 2012
- Posts
- 14
- Rep Power
- 0
Re: FileNotFoundException when attempting to save android game
ahhh ok, thank you for your help
- 01-17-2013, 03:59 AM #6
Similar Threads
-
how to save and load and pause a game ?
By paris72 in forum Java GamingReplies: 3Last Post: 07-03-2012, 03:58 AM -
Simple loading txt android file throws FileNotFoundException
By Addez in forum AndroidReplies: 0Last Post: 02-17-2012, 09:13 PM -
Eclipse vs Netbeans for android game
By beast in forum New To JavaReplies: 5Last Post: 12-30-2011, 08:48 PM -
Another math game, attempting oop
By Nanomech in forum New To JavaReplies: 11Last Post: 12-13-2011, 11:41 PM -
Simple Android Game Design
By fresh83 in forum New To JavaReplies: 1Last Post: 05-16-2011, 05:40 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks