12-22-2009 12:53 PM
I'm using a connection to connect to my SDcard and see if there is an image. If not the script creates the image, if so it will delete the image and then create it. The script works fine when ran the first few times. After that though it seems as if it will not close the connection to the SDcard.
It's stops wirting / reading the card. My device still sees the card as being in the device but I have no way to aceess it. When I open the card up there are no files or anything on it. The device says the card is blank. If I remove the card though and put it back in everything works with it again. Here is the code I'm using can you guys see anything wrong with it?
String path = "file:///SDCard/BlackBerry/pictures/sw.jpg";
FileConnection FileConn = null;
try{
FileConn = (FileConnection) Connector.open(path,Connector.READ_WRITE);
if(!FileConn.exists()){
FileConn.create();
}
FileConn.setWritable(true);
PNGEncoder encoder = new PNGEncoder(bg);
java.io.OutputStream output = FileConn.openOutputStream();
output.write(encoder.encode(true));
output.close();
HomeScreen.setBackgroundImage(path);
} catch(Exception e){
System.out.println("Image Error: " + e);
} finally {
try{ FileConn.close(); } catch(Exception e){}
}
Solved! Go to Solution.
12-22-2009 02:17 PM
Just a guess, maybe try calling setBackgroundImage after closing FileCon. Also, just as a opinion, to make everything "fit together" better the path should end with png (don't think that would cause any issues with setBackgroundImage but don't know) and setWritable is not needed unless there is a chance that the image/path is readonly.
12-23-2009 02:01 PM
rcmaniac25 wrote:Just a guess, maybe try calling setBackgroundImage after closing FileCon. Also, just as a opinion, to make everything "fit together" better the path should end with png (don't think that would cause any issues with setBackgroundImage but don't know) and setWritable is not needed unless there is a chance that the image/path is readonly.
Okay I tried calling the setBackground after the connection closes. I also removed the setWritable and changed the jpg to png.
Everything works just fine, but after like 2-3 hours the SDcard starts acting up again. I'm not sure what is causing it but for some reason it's not being closed. Does anyone else have any suggestions?
Thanks
12-23-2009 03:38 PM
Wait, it works for some time then stops working? Are you testing this on a real device or the simulator?
12-23-2009 10:39 PM
rcmaniac25 wrote:Wait, it works for some time then stops working? Are you testing this on a real device or the simulator?
Yes the code works just fine for a while but then quits.
I have this code run in the background every 15,30,45 or 60 minutes (ther user can pick how often it updates). Anyways it will update just fine for like an hour or so and then for some reason the SDcard will not respond after that. I'm using this on the real device not the simulator. It seems to me like the SDcard connection never gets closed for some reason and then becomes unavailable. I'm not sure what it is but I can't seem to get any errors or anything like that on the simulator.
12-23-2009 11:04 PM
Okay I found the issue. I had an inputstream that I forgot to close porperly. So after X amount of times running the app wouldn't allow me to open anymore streams. I closed it properly and everything is running smooth now.
12-24-2009 12:53 AM
Good, if your issue is resolved then mark whatever post helped you (if any) as the solution so anyone else that has this issue can see what fixed the issue.