我想从pokeAPI获得我的android的数据。我已按照说明进入本页https://github.com/PokeAPI/pokekotlin。
我添加了bluid.gradle(模块:app)依赖项:
compile 'me.sargunvohra.lib:pokekotlin:2.3.0'在build.gradle(项目)中:
allprojects {
repositories {
google()
jcenter()
maven { url 'http://jcenter.bintray.com' }
}}
我在清单中添加了此权限:
<uses-permission android:name="android.permission.INTERNET" />获取口袋妖怪物种的代码位于异步任务中:
private class DownloadPokeAPIData extends AsyncTask<Integer,Void,PokemonSpecies> {
protected PokemonSpecies doInBackground(Integer...numbers){
PokeApi pokeApi = new PokeApiClient();
try {
return pokeApi.getPokemonSpecies(numbers[0].intValue());
}catch(Exception e){
Log.e("AsyncTask error",e.getMessage());
}
return null;
}
protected void onPostExecute(PokemonSpecies result) {
if(result != null) ((TextView)findViewById(R.id.pokemon)).setText(result.getName());
}
}DownloadPokeAPIData的调用在onCreate of MainActivity:new DownloadPokeAPIData().execute(new Integer(1));中
但我还是收到了这样的信息:
AsyncTask error: Unable to resolve host "pokeapi.co": No address associated with hostname你知道问题出在哪里吗?
发布于 2017-12-13 13:47:41
我读过this,我必须在我的清单中添加这个权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />现在是工作了。谢谢你的答复。
https://stackoverflow.com/questions/47779683
复制相似问题