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
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various
Accepted Solution

Unable to display image from web on blackberry device

i developed simple code to display an image and title on blackberry screen,but i am not able to display anything( but if i tested for title only it is working)my requirement is to display image with title in a list? i have followed

this link for fetching image from image url

 

and here my code in drawlistrow method:

 

public void drawListRow(ListField list, Graphics g, int index, int y, int w)
        {
            String text = (String)listElements.elementAt(index);
            Bitmap image =GetImage.connectServerForImage("http://toucheradio.com/toneradio/iphone/toriLite/toriLive.png");
            g.drawLine(0, y, w, y);

            g.drawText(text, 150, y, 60, w);
            g.drawBitmap(0,y,image.getWidth(),image.getHeight(),image,0,0);
        }

can any one what will be the problem?

 

Highlighted
Developer
Posts: 16,998
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Unable to display image from web on blackberry device

Blocking operations, such as web access, should not be done on the event thread.
see
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

in this case it is even worse, as drawListRow is called for every list row.

download the pictures on a separate thread, you can update the listfield after they are ready.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: Unable to display image from web on blackberry device

now ,i have downloaded the image in a separate thread ,i have used  directly the bitmap reference in my drawlistrow method 

g.drawBitmap(0,y,bitmap_ref.getWidth(),bitmap_ref..getHeight(),bitmap_ref.,0,0);
but still i am unable to display my list row

 

here my code:

private class Connection extends Thread {
        
public void run() {
            
try {
conn = (StreamConnection) Connector
    .open("http://toucheradio.com/toneradio/android/toriLite/toriplaylist.xml"
                                + ";deviceside=true");
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
        .newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
docBuilderFactory.setCoalescing(true);
DocumentBuilder docBuilder = docBuilderFactory
        .newDocumentBuilder();
docBuilder.isValidating();
is = conn.openInputStream();
doc = docBuilder.parse(is);
doc.getDocumentElement().normalize();
                
NodeList list = doc.getElementsByTagName("image");
for (int a = 0; a < list.getLength(); a++) {
Node textNode1 = list.item(a).getFirstChild();
imageurl = textNode1.getNodeValue();
Bitmap image=GetImage.connectServerForImage(imageurl);
listImage.addElement(image);
}

Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: Unable to display image from web on blackberry device

in my question ,i tried to display single image with one list item, i dont know why it is not working?

Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: Unable to display image from web on blackberry device

Hii,

      i got my requirement ,if append this(";deviceside=true") to at the end of   my image web url like this   imageweburl+";deviceside=true",then it is working