如何解决方法调用“ toString”可能会产生“ java.lang.NullPointerException”?

时间:2019-04-04 01:01:45

标签: java broadcastreceiver uri

当我尝试收到 [HttpGet("[action]")] public async Task<string> GET(string url) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Headers.Add("Authorization", BearerToken); try { WebResponse response = request.GetResponse(); using (Stream responseStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.UTF8); return reader.ReadToEnd(); } } catch (WebException ex) { WebResponse errorResponse = ex.Response; using (Stream responseStream = errorResponse.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8")); String errorText = reader.ReadToEnd(); } throw; } } 的更新时尝试接收App时,出现此错误。

在BroadcastReveiver.java

Uri

Uri packageName = new Intent ().getData (); If (packageName.toString ().equals ("package:" + context.getPackagName ())){ //do something } 发生错误方法调用'toString'可能会产生'java.lang.NullPointerException'

有人可以帮助我或使用连击方式接收更新吗?

0 个答案:

没有答案