2011-09-17 68 views
0

我有这个班我的应用程序:应用工作在模拟器,但不是在设备

  1. NewsApp.java
  2. ScreenApp.java
  3. Item.java
  4. ui/TableList.java

该应用程序检索列表来自web服务(.net)的链接,我使用KSoap库(作为参考项目)。

我用JDE 4.5开发,因为与Eclipse我不能使用的方法“setRowHeight(索引,INT)” ListField类的,那么我就需要用JDE 4.5

好吧,我编译应用程序(F7键),然后在模拟器(F5键)中运行。 在模拟器中,转到图标应用程序,并尝试打开...没有发生...应用程序未打开...很奇怪...没有错误消息(ScreenApp.java第57行)...但.. 。如果我再多几分钟...我看到错误信息(ScreenApp.java第57行)...我想也许是因为应用程序尝试连接...

后来...我想是因为不存在在模拟器中的互联网连接(我看到模拟器顶部的EDGE ...很奇怪),我停止模拟器,打开MDS,并再次运行模拟器(F5键),现在工作...列表显示正确.. 。我可以打开黑莓浏览器中的链接。现在

...我把所有编译后的文件在同一目录下,创建一个ALX文件:

  1. NewsApp.alx 并在设备上安装此应用,工程安装好了,我去的应用程序列表上设备(8520),打开应用程序,我看到连接消息(ScreenApp.java第57行); 我不明白为什么?在这个电话(8​​520)我有我的运营商的EDGE连接,我有WIFI活动...我可以浏览任何网页(默认浏览器)...但我的应用程序不能从webservice检索信息... :(

有人帮帮我好吗?

+0

抛出的异常的类型和异常中包含的任何消息可能会告诉我们什么是错误的很长一段路。根据您对模拟器的使用经验,我期望它与您使用的连接方法有关。 – Richard

+0

而且......我该如何解决这个问题:S? 解决这个问题的方法是什么? 我需要使用什么方法? 因为在示例中我需要在try catch中添加调用方法 – jfrubiom

+0

在您的catch子句(ScreenApp.java第57行)中,在您的输出中包含Exception的内容和类型,并将其报告在此处。 e.toString()会工作。编写一本关于Java编程的好书可能也有帮助。 – Richard

回答

0

您需要在网址的结尾,当在设备上运行的应用程序。

对于离,在无线网络的情况下,就需要追加使用不同的连接参数; interface = wifi“ at the end of the URL。

详细代码是:您需要根据设备网络调用getConnectionString()来获取连接sufix。我希望这会解决你的问题。

/** 
    * @return connection string 
    */ 
    static String getConnectionString() 
    { 
     // This code is based on the connection code developed by Mike Nelson of AccelGolf. 
     // http://blog.accelgolf.com/2009/05/22/blackberry-cross-carrier-and-cross-network-http-connection   
     String connectionString = null;     

     // Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR variable. 
     if(DeviceInfo.isSimulator()) 
     {    
      // logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is true"); 
      connectionString = ";deviceside=true";       
     }           

     // Wifi is the preferred transmission method 
     else if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) 
     { 
     // logMessage("Device is connected via Wifi."); 
      connectionString = ";interface=wifi"; 
     } 

     // Is the carrier network the only way to connect? 
     else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) 
     { 
      //logMessage("Carrier coverage."); 

      String carrierUid = getCarrierBIBSUid(); 
      if(carrierUid == null) 
      { 
       // Has carrier coverage, but not BIBS. So use the carrier's TCP network 
      // logMessage("No Uid"); 
       connectionString = ";deviceside=true"; 
      } 
      else 
      { 
       // otherwise, use the Uid to construct a valid carrier BIBS request 
      // logMessage("uid is: " + carrierUid); 
       connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public"; 
      } 
     }     

     // Check for an MDS connection instead (BlackBerry Enterprise Server) 
     else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) 
     { 
     // logMessage("MDS coverage found"); 
      connectionString = ";deviceside=false"; 
     } 

     // If there is no connection available abort to avoid bugging the user unnecssarily. 
     else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) 
     { 
      //logMessage("There is no available connection."); 
     } 

     // In theory, all bases are covered so this shouldn't be reachable. 
     else 
     { 
      //logMessage("no other options found, assuming device."); 
      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; 
    } 
+0

嗨,感谢您的回复,我已完成与HttpConnectionFactory这一步...设备上的应用程序的作品,但只与WIFI,如果我尝试使用EDGE连接不起作用...,当我尝试导航(默认浏览器)的asmx网址,我什么也不能显示...我看到连接超时错误...也许是这个原因...当我尝试从我的应用程序调用这个web服务不工作...该应用程序只能工作与WIFI ...我需要与EDGE和3G作品 – jfrubiom

+0

您可以尝试上面的代码作为示例应用程序,也许这将对您有所帮助。 –

相关问题