我正在試圖製作一個應用程序,讓我使用Riot Games API跟蹤遊戲英雄聯盟中某個用戶的統計數據。我已經制定了一種方法,可以讓我分析服務器的勝負數,並計算它們之間的比率,但是我需要從onCreate或其他可以調用的方法中調用它的onCreate。如何調用具有onCreate參數的方法?
這裏是方法:
public static void checkStats(String[] args) throws RiotApiException {
RiotApi api = new RiotApi("DEVELOPER KEY REDACTED");
Summoner summoner = api.getSummonerById(Region.EUW, "ID REDACTED");
RankedStats statsRanked = api.getRankedStats(Region.EUW, summoner.getId());
AggregatedStats rankedStats = statsRanked.getChampions().get(0).getStats();
wins = rankedStats.getTotalSessionsWon();
losses = rankedStats.getTotalSessionsLost();
ratio = wins/losses;
ratioView.setText(wins + "/" + losses + " | " + "Ratio : " + ratio);
}
勝,損失率和ratioView都在上面的代碼中定義:
static int points, wins, losses, ratio, BOtarget, BOwins, BOlosses, BOprogress;
static TextView ratioView;
我試圖通過使用這條線來調用此方法,但它說checkstats(String [])不能應用於checkstats():
checkStats();
所以我試着用:
checkstats(null);
但現在,我得到一個未處理的異常:
Unhandled exception: net.rithms.RiotApiException
相關API的所有進口正確。
僅供參考,我下面這個例子:https://github.com/taycaldwell/riot-api-java/blob/master/examples/RankedWinsAndLosses.java
謝謝您的幫助。
編輯:整個活動碼:http://pastebin.com/2f65WTWN
你不需要讓它們變成靜態的。你需要的是'AsyncTask'來在主線程後面進行API調用。我不確定'Riot'是否處理異步。或不。 – adnbsr
你好,我試圖做到這一點:https://gyazo.com/1cac084a4fcd5c651136fc0475dd7722但現在我不知道如何從onCreate調用一個類。任何關於代碼的想法/從onCreate調用類的幫助? –