search

Home  >  Q&A  >  body text

Android okhttp网络请求框架 获取失败信息闪退了

使用的OkHttp框架做网络请求,但是在onFailure的方法中一句打印失败信息的代码报错了

错误的信息

报错的地方

求指教

伊谢尔伦伊谢尔伦2773 days ago719

reply all(4)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:55:15

    e.getMessage() is null, change it to:

    e.toString()
    

    In fact, e.getMessage() is of String type, so there is no need to toString() again.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:55:15

    This is a very common Java null pointer exception. It has nothing to do with okhttp. Not all exceptions have messages, so getMessage() cannot guarantee that it is not null, so don’t use it directly.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:55:15

    Print e.printStackTrace() directly in the onFailure callback function to determine where the IO exception occurred based on the log, and then you can follow the clues to find the problem

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:55:15

    Null pointer exception should not have much to do with okhttp. It may be that there is something wrong with your line of code. Please change the way of writing or thinking.

    reply
    0
  • Cancelreply