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

BlackBerry Rss Feed Not loading on Device

[ Edited ]

I have  developed Rss Feed reader Application ,when I execute the App on BB Simulator 9900,I'm able to display the List Items Successfully,

 

But the same App when I try to execute on my Real Device BB Curve 9380,I'm not able to load my List Items.

 

Could any one tell me what went Wrong?

 

Here My Code:

 
public class RssScreen extends MainScreen implements ListFieldCallback {

 public RssScreen() {
           
   subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL
    | Manager.VERTICAL_SCROLLBAR) {
    protected void sublayout(int maxWidth, int maxHeight) {
    int displayWidth=Display.getWidth();
    int displayHeight = Display.getHeight();
    super.sublayout(displayWidth, displayHeight);
    setExtent(displayWidth, displayHeight);
    }
    };
      
   _list = new ListField()
  {
   protected boolean navigationClick(int status, int time) {
    return true;
   }
   public void paint(Graphics graphics)
   {
    graphics.setColor((int) mycolor);
    super.paint(graphics);
   }
    };
   mycolor = 0x00FFFFFF;
  _list.invalidate();
  _list.setEmptyString("* Feeds Not Available *", DrawStyle.HCENTER);
  _list.setRowHeight(70);
  _list.setCallback(this);
  //mainManager.add(subManager);
  add(subManager);
    
    
  listElements.removeAllElements();
  _connectionthread = new Connection();
  _connectionthread.start();
   }
          /*RssFileReading in a Seperate Thread*/
   private class Connection extends Thread {
  public Connection() {
   super();
   }
  public void run() {
   Document doc;
   StreamConnection conn = null;
   InputStream is = null;
   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 listImg = doc.getElementsByTagName("title");
    for (int i = 0; i < listImg.getLength(); i++) {
     Node textNode = listImg.item(i).getFirstChild();
     listElements.addElement(textNode.getNodeValue());
    }
    NodeList list = doc.getElementsByTagName("image");
    for (int a = 0; a < list.getLength(); a++) {
     Node textNode1 = list.item(a).getFirstChild();
     String imageurl = textNode1.getNodeValue();
     Bitmap image = GetImage.connectServerForImage(imageurl
       .trim() + ";deviceside=true");
     listImage.addElement(image);
    }
      } catch (Exception e) {
    System.out.println(e.toString());
   } finally {
    if (is != null) {
     try {
      is.close();
     } catch (IOException ignored) {
     }
    }
    if (conn != null) {
     try {
      conn.close();
     } catch (IOException ignored) {
     }
    }
   }
   UiApplication.getUiApplication().invokeLater(new Runnable() {
    public void run() {
     _list.setSize(listElements.size());
     subManager.add(_list);
     invalidate();
    }
   });
   } }
/*This Method is Invoked for Each title on RssFile*/
 public void drawListRow(ListField list, Graphics g, int index, int y,
   int width) {
  String title = (String) listElements.elementAt(index);
  Bitmap image = (Bitmap) listImage.elementAt(index);
  try {
 
   g.drawBitmap(xpos, ypos, w, h, image, 0, 0);
   xpos = w + 20;
   g.drawText(title, xpos, ypos);
    } catch (Exception e) {
     e.printStackTrace();
    }
    }
 }

 

Note:when I run the application on my real device ,I'm displayed with * Feeds Not Available * Message on Screen

 

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: BlackBerry Rss Feed Not loading on Device

In future when you ask general questions like this can you please be as precise as possible.  For example in this case you could describe any exceptions that you, and what happens when you step through the code that works on the Simulator and fails on the real device.  Otherwise we are just guessing at your problem in amongst the many lines of code you have given us.

 

In this case I am pretty sure your problem is in your connection.  You need to understand how to connect on a real device better.  ";deviceside=true" working on the Simulator but may or may not work on a device. 

 

To understand the networking possibilities, you need to review the following:

 

http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742

 

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

And I recommend, assuming your targeting OS 5.0 and above, that you use ConnectionFactory to connect.  Review the API documentation. 

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

Re: BlackBerry Rss Feed Not loading on Device

Thanks for reply,I had debugged my app on real device ,I'm getting the error message that "APN is not specified" ,could you please tell me what should I change in my code?
Highlighted
Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: BlackBerry Rss Feed Not loading on Device

In this KB article that I referenced in my last post:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

It points out that by using ";deviceside=true" you are using Direct TCP.  Review that section and the other KB article that is referenced in that section to understand what you need to change in your code - if in fact you can change it in your code - I suspect you may not know what values to set.  In which case, please review the references I gave you again - you may consider using WiFi or WAP2, both of which do not need any setup.