2011-09-17 38 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

您可以嘗試上面的代碼作爲示例應用程序,也許這將對您有所幫助。 –

相關問題