我試圖在我的程序中實現tTorrent客戶端,我已經看過這個鏈接的例子(https://github.com/mpetazzoni/ttorrent/issues/16),並將該代碼放到我的程序的Download類中。下面是代碼:tTorrent客戶端錯誤
import語句:
import main.java.com.turn.ttorrent.client.Client;
import main.java.com.turn.ttorrent.client.SharedTorrent;
import main.java.com.turn.ttorrent.common.Torrent;
import main.java.com.turn.ttorrent.tracker.TrackedTorrent;
import main.java.com.turn.ttorrent.tracker.Tracker;
// Create tracker instance
Tracker tracker = new Tracker(InetAddress.getLocalHost());
// Load torrent file
File torrentFile = new File("/path/to/torrentFile.torrent");
// Create torrent instance
TrackedTorrent torrent = new TrackedTorrent(Torrent.load(torrentFile, null));
// Announce torrent
tracker.announce(torrent);
// Start the tracker
tracker.start();
torrentFile = new File(path + ".torrent");
File downloadDir = new File("/path/to/torrents_download_dir");//unsure
Client client = new Client(InetAddress.getLocalHost(), SharedTorrent.fromFile(torrentFile, downloadDir));
// Add client.share(); if you wish to share the torrent infinitely
client.run();
我收到此錯誤信息,當我將鼠標懸停在負載:
The method load(File, boolean) in the type Torrent is not applicable for the arguments (File, null)
我也不能確定,我應該在File downloadDir
地方。我仍然是一名初學者,如果有人能指出我正確的方向,將其納入我的計劃中將會很棒。我還是個初學者。
學會解讀錯誤消息的對象和方法。沒關係。加載需要一個布爾值,並且你將它賦值爲null。 – Brendan
我知道如何解釋錯誤信息。在發佈問題之前,我嘗試將其設置爲false,但它給了我錯誤消息「構造函數TrackedTorrent(Torrent)未定義」。此外,由tTorrent提供的gitHub鏈接上給出的示例將其作爲null。還有一個人發佈了與你相同的答案,並將其刪除,因爲我們沒有得到任何地方。 – Joe