UnknownHostException: name or service not known

后端 未结 3 2316
时光说笑
时光说笑 2021-02-20 08:28

I\'m attempting to return some data from an API using OkHttpClient in com.squareup.okhttp. I\'ve run into a few errors that i have eventually been able to overcome but i can\'t

3条回答
  •  醉酒成梦
    2021-02-20 08:36

    For error like "java.net.UnknownHostException: [hostname]"

    The reason is your hostname is not in /etc/hosts, The solution is simple:

    sudo vim /etc/hosts
    

    change the line looks like:

    127.0.0.1  localhost
    

    to:

    127.0.0.1  [hostname] localhost
    

    Save and exit. If the problem still exist, may be you need to restart or run :

    sudo ifconfig eth0 down&&sudo ifconfig eth0 up
    

    Hope it can help you!

提交回复
热议问题