0

我开发了 RSS Feed 阅读器应用程序,当我在 BB Simulator 9900 上执行应用程序时,我能够成功显示列表项,

但是当我尝试在我的真实设备 BB 曲线 9380 上执行相同的应用程序时,我无法加载我的列表项。

谁能告诉我出了什么问题?

注意:当我在我的真实设备上运行应用程序时,我会显示* Feeds Not Available *屏幕上的消息

这是我的代码:

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();
    }
    }
 }
4

1 回答 1

2

从上面的评论中,很明显问题出在连接字符串上。在 url 末尾附加 http 连接字符串并尝试。

conn = (StreamConnection) Connector .open("http://toucheradio.com/toneradio/android/toriLite/toriplaylist.xml"
    +getConnectionString() );

下面getConnectionString()给出-

private static String getConnectionString()
{
    String connectionString = null;
    // Wifi is the preferred transmission method
    f(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
    {
        connectionString = ";interface=wifi";
    }
    // Is the carrier network the only way to connect?
    else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
    {
        String carrierUid = getCarrierBIBSUid();
        if(carrierUid == null)
        {
            // Has carrier coverage, but not BIBS.  So use the carrier's TCP network
            connectionString = ";deviceside=true";
        }
        else
        {
            // otherwise, use the Uid to construct a valid carrier BIBS request
            connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
        }
    }
    // Check for an BIS connection
    else  if (TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_BIS_B) && TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_BIS_B)) {
        connectionString = ";deviceside=false;ConnectionType=mds-public";
    }
    // Check for an MDS connection instead (BlackBerry Enterprise Server)
    else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
    {
        connectionString = ";deviceside=false";
    }
    // If there is no connection available abort to avoid bugging the user unnecssarily.
    else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
    {
        //no connection available
    }
    // In theory, all bases are covered so this shouldn't be reachable.
    else
    {
        connectionString = ";deviceside=true";
    }
    return connectionString;
}

/**
* Looks through the phone's service book for a carrier provided BIBS network
* @return The uid used to connect to that network.
*/
private static String getCarrierBIBSUid()
{
    ServiceRecord[] records = ServiceBook.getSB().getRecords();
    int currentRecord;
    for(currentRecord = 0; currentRecord < records.length; currentRecord++) 
    {             
        if(records[currentRecord].getCid().toLowerCase().equals("ippp")) 
        {                  
            if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
            {
                return records[currentRecord].getUid();
            }
        }
    }
    return null;
} 
于 2013-02-23T07:11:18.420 回答