Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
welsenKiriono
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: Multithreading file image loader

Hi...

I'm already trying to use the code but i got IOException (File system error (1000))

Here is the code

 

try {
   fileGroup = new TagGroup(FileConnectionLibrary.openFile("file:///SDCard/BlackBerry/system/media/thumbs116x116.dat")
  , FileConnectionLibrary.ISlength);
} catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}

 

this is my FileConnectionLibrary

 

public class FileConnectionLibrary{
  private static FileConnection fconn;
  private static InputStream iS;
  private static byte[] data;
  public static int ISlength;

  public static InputStream openFile(String path)
  {
    InputStream result = null;
    try {
	fconn = (FileConnection)Connector.open(path,  Connector.READ_WRITE);
	if (fconn.exists())
	{
	  iS = fconn.openInputStream();
	  result = iS;
	  data = IOUtilities.streamToBytes(iS);
	  ISlength = data.length;
	}
    } catch (IOException e) {
 	ISlength = 0;
    }
    finally {
      try {
       	iS.close();
     	fconn.close();
      } catch (IOException e) {}
    }	
    return result;	
}

 

can you help me, please?

 

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Multithreading file image loader

Can you trace to see where it is coming from since it seems like a very generic exception.

 

Also you can simply call fileSize() on FileConnection to get the file size.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
welsenKiriono
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: Multithreading file image loader

hi... the problem is lying in Tag Class

If I'm using this code in TagGroug

 

DataInputStream br = new DataInputStream(st);
int smallEdnian = 1570;
if (br.readShort() != smallEndian) //8710 for big-endian { //Not valid dataBase return; }

it's not valid database

 

but if i'm using big-endian (8710), my error is in Tag Class

 

public Tag(DataInputStream br) throws IOException
    {
        Reserved1 = TagGroup.reverseEndian(br.readShort());
        PathLength = TagGroup.reverseEndian(br.readInt());
        NameLength = TagGroup.reverseEndian(br.readInt());
        DataLength = TagGroup.reverseEndian(br.readInt());
        Reserved2 = TagGroup.reverseEndian(br.readInt());
        Reserved3 = TagGroup.reverseEndian(br.readInt());
        Reserved4 = TagGroup.reverseEndian(br.readInt());
        int b = br.read(); //Gap (0)
        Path = new String(TagGroup.readChars(br, PathLength));
        Name = new String(TagGroup.readChars(br, NameLength));

 

when accessing path, i got an error java.lang.OutOfMemoryError..

 

 

 

 

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Multithreading file image loader

Hmm, I wonder if they updated the number. Need to check again.

 

Since it was demonstration code it didn't really take error checking into account.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Multithreading file image loader

I made a bunch of mistakes that I didn't catch (I don't know how I even got it to work) and fixed the code. It's posted the updated code to the same thread that the original code came from:

http://supportforums.blackberry.com/t5/Java-Development/BBThumbs-dat/m-p/1075317/message-uid/1075317...

 

Let me know if you get any issues from that. Also, being that it's just demonstration code, you might want modify the code to skip the data and just take the names and paths. Calculate an offset at the time of tag creation, then when the image is necessary, read it in. I say this because when I tried to read the 480x480 thumbs (for testing purposes) I got OutOfMemory exceptions. I don't know how many images some people have but you never know what might happen. Also I stand corrected (can't edit previous post), pre-5.0 the thumbs were in PNG format, for the thumbnail files I checked (Storm2, 5.0) they where JPEGs. Just use EncodedImage and everything will be fine.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
welsenKiriono
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: Multithreading file image loader

Thanx for the code,

The problem is i still got out of memory error...

But, when i'm debugging it, i can fet some of the image, but after that out of memory occured..

i've tried to call system.gc for everytime i instance a new tag class, but still got the problem...

Any solution for handle this error?

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Multithreading file image loader

That's basically what I said in the second part of my previous post. You'll get out of memory exceptions. You need to come up with your own version that only loads what is visible on your image loader. This way you don't load (in my case) over 3500 480x480 images at the same time.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.