我正在制作一款使用Riot Games API的应用。我输入这行代码以获得他们网站的回复:
public int getSummonerLevel() throws JSONException, UnirestException {
GetRequest gr = Unirest.get("https://na.api.pvp.net/api/lol/" + region + "/v1.4/summoner/by-name/" + summonerName + "?api_key=43f88d5a-a1ad-4a8c-ae5a-9fb2d81e471a");
HttpResponse<JsonNode> node = gr.asJson();
String summonerInfo = node.getBody().toString();
JSONObject obj = new JSONObject(summonerInfo);
int summonerLevel = obj.getJSONObject(summonerName).getInt("level");
return summonerLevel;
}
但是,我收到此错误
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicLineFormatter; in class Lorg/apache/http/message/BasicLineFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicLineFormatter' appears in /system/framework/ext.jar)
在这一行:
HttpResponse<JsonNode> node = gr.asJson();
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.ryanfolz.riotgamesapi"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/commons-codec-1.6.jar')
compile files('libs/commons-logging-1.1.3.jar')
compile files('libs/httpasyncclient-4.0.2.jar')
compile files('libs/httpasyncclient-cache-4.0.2.jar')
compile files('libs/httpclient-4.3.5.jar')
compile files('libs/httpclient-cache-4.3.5.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpcore-nio-4.3.2.jar')
compile files('libs/httpmime-4.3.jar')
compile files('libs/org.json-20120521.jar')
}
这可能是一个问题,依赖关系不兼容android?我在Eclipse中运行了这段代码,它对我来说效果很好。