2013-05-29 82 views
0

我正在嘗試使用ttorrent庫爲android創建torrent應用程序。 我有一些問題。ttorrent庫HttpResponseMessage錯誤

05-29 23:07:23.388:E/AndroidRuntime(3681):致命異常:BT-宣佈(.. 393337)

05-29 23:07:23.388:E/AndroidRuntime( 3681):java.lang.NullPointerException

05-29 23:07:23.388:E/AndroidRuntime(3681):at com.turn.ttorrent.common.protocol.http.HTTPAnnounceResponseMessage.parse(HTTPAnnounceResponseMessage.java:105 )

05-29 23:07:23.388:E/AndroidRuntime(3681):at com.turn.ttorrent.common.protocol.http.HTTPTrackerMessage.parse(HTTPTrackerMessage.java:51)

05-29 23:07:23.388:E/AndroidRuntime(3681):在com.turn.ttorrent.client.announce.HTTPTrackerClient.announce(HTTPTrackerClient.java:124)

05-29 23: 07/23.388:E/AndroidRuntime(3681):at com.turn.ttorrent.client.announce.Announce.run(Announce.java:224)

05-29 23:07:23.388:E/AndroidRuntime(3681) ):在java.lang.Thread.run(Thread.java:856)

public static HTTPAnnounceResponseMessage parse(ByteBuffer data) 
    throws IOException, MessageValidationException { 
    BEValue decoded = BDecoder.bdecode(data); 
    if (decoded == null) { 
     throw new MessageValidationException(
      "Could not decode tracker message (not B-encoded?)!"); 
    } 

    Map<String, BEValue> params = decoded.getMap(); 

    try { 
     List<Peer> peers; 

     try { 
      // First attempt to decode a compact response, since we asked 
      // for it. 
      peers = toPeerList(params.get("peers").getBytes()); 
     } catch (InvalidBEncodingException ibee) { 
      // Fall back to peer list, non-compact response, in case the 
      // tracker did not support compact responses. 
      peers = toPeerList(params.get("peers").getList()); 
     } 

     return new HTTPAnnounceResponseMessage(data, 
      params.get("interval").getInt(), 
      params.get("complete").getInt(), 
      params.get("incomplete").getInt(), 
      peers); 
    } catch (InvalidBEncodingException ibee) { 
     throw new MessageValidationException("Invalid response " + 
      "from tracker!", ibee); 
    } catch (UnknownHostException uhe) { 
     throw new MessageValidationException("Invalid peer " + 
      "in tracker response!", uhe); 
    } 

沒有鍵,例如「INTERV al「或」complete「或」inclomplete「是params。有兩個鍵「同級」和「最小間隔」。

據我調用客戶端方法下載後,它從跟蹤器請求一些信息,然後嘗試解析這些信息。這就是錯誤所在。

所以,問題是爲什麼這樣呢?在圖書館裏是錯誤還是我有什麼問題?

回答

1

究竟是什麼問題?

請編輯您的問題並添加更多詳情。

理想情況下包括一個sscce

添加到您的問題的一個鏈接到一個洪流文件,顯示此錯誤。 你是如何建立ttorrent?

確認您看到的錯誤是從Android運行時發生的,並且不會在純Java中發生。

您可以使用git從github獲取tTrent代碼或單擊github項目上的按鈕來下載zip文件。

ttorrent使用maven。如果您手動獲取相關性,則可能無法獲得正確的版本。 您應該將代碼作爲maven項目導入Eclipse。 Eclipse - >文件 - > ...導入 - > Maven - >現有Maven項目

在導航器窗格中。找到ttorrent項目並右鍵單擊選擇運行方式 - > Maven Build ... 對於「包」中的目標類型並單擊「運行」。

我開始使用ttorrent示例客戶端,並將路徑添加到已知好的Ubuntu 13.04 torrent file以及保存到的目錄中。

我在調試器中運行了代碼,並且tTrent的功能正確。它開始下載Ubuntu而不會拋出異常或打印錯誤消息。

在你列出的行中,我看到PARAMS地圖有四個條目(「interval」,「complete」,「peers」,「incomplete」)。

這裏是我使用的客戶端代碼:

public class ClientTest 
{ 

    public static void main(String[] args) throws NoSuchAlgorithmException 
    {  
     try { 
      SharedTorrent fromFile = 
      SharedTorrent.fromFile(
      new File("j:/ubuntu-13.04-desktop-amd64.iso.torrent"), 
      new File("j:/td")); 
      Client client = 
       new Client(InetAddress.getLocalHost(), fromFile); 
      client.download(); 
      client.waitForCompletion(); 
     } catch (UnknownHostException ex) { 
      Logger.getLogger(ClientTest.class.getName()).log(Level.SEVERE, null, ex); 
     } catch (IOException ex) { 
      Logger.getLogger(ClientTest.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 

} 
+0

那麼,究竟你「從ttorrent例如開始」。 因爲在我下載了文件之後,我在Eclipse中創建了一個新項目。然後我將所有文件複製粘貼到我的src目錄。 然後下載了所有的jar包,比如簡單的框架,commons.io等等。 我可以在TrackerService類中看到錯誤。 response.setText(「Not Found」); 給出錯誤。 Resoponse根本就沒有這種方法。 – user1685095