异常java.lang.RuntimeException:无法启动活动 ComponentInfo {} app.app/app.app.activity.NotificacaoActivity: java.lang.NullPointerException:尝试从字段读取 'java.lang.String app.app_ [REDACTED_DOMAIN_NAME]'为空 对象参考
由java.lang.NullPointerException引起:尝试从字段读取 'java.lang.String app.app_ [REDACTED_DOMAIN_NAME]'为空 对象参考 app.app.persistence.WAPIService.getNotificacoes (WAPIService.java:230) app.app.activity.NotificacaoActivity.onStart (NotificacaoActivity.java:65)
我无法理解这个错误是什么,下面,它遵循错误引用的类: Notificacao:
@Override
public void onStart() {
super.onStart();
showProgress(true, "wait", false);
WAPIService.getInstance().getNotificacoes(new FutureCallback<List<Notificacao>>() {
@Override
public void onSuccess(List<Notificacao> result) {
//listView.setAdapter(new NotificacaoAdapter(getContext(), result));
if(!result.isEmpty()) {
List<Notificacao> lidas = new ArrayList<Notificacao>();
List<Notificacao> naoLidas = new ArrayList<Notificacao>();
for(Notificacao n : result){
if((n.Status == 10 && n.Tipo != 5 && n.Tipo != 10 && n.Tipo != 15 && n.Tipo != 20) ){//Teste com 20 para dividir
naoLidas.add(n);
} else {
lidas.add(n);
}
}
if (getFragmentRefreshListenerLidas() != null) {
getFragmentRefreshListenerLidas().onRefresh(new NotificacaoAdapter(getContext(), lidas));
}
if (getFragmentRefreshListenerNaoLidas() != null) {
getFragmentRefreshListenerNaoLidas().onRefresh(new NotificacaoAdapter(getContext(), naoLidas));
}
}
showProgress(false, "", true);
}
@Override
public void onFailure(Throwable t) {
showProgress(false, "", true);
Toast("Erro ao buscar notificações");
Log.e(TAG, "Erro ao buscar notificações: " + t.getMessage());
}
});
}
Wapi技术: 这个类进入服务器,我寻找通知:
public void getNotificacoes(final FutureCallback&gt; callback){ JsonObject usuarioId = new JsonObject(); usuarioId.addProperty(“id_usuario”,((ApplicationUtils)context.getApplicationContext())。getUsuario()。Id);
wapiConn.invokeApi("notification", "get", usuarioId, JsonObject.class, new FutureCallback<JsonObject>() {
@Override
public void onSuccess(JsonObject result) {
try {
List<Notificacao> notificacoes = JsonEntityParser.parseResults(result.getAsJsonArray("notifications"),
wapiConn.getMobileServiceClient().getGsonBuilder().create(), Notificacao.class);
//Chamando CallBack da tela de login / registro
callback.onSuccess(notificacoes);
} catch (Exception e) {
callback.onFailure(e);
}
}
@Override
public void onFailure(Throwable t) {
callback.onFailure(t);
}
});
}
答案 0 :(得分:0)
似乎调用 context.getApplicationContext())。getUsuario()返回null,并在尝试获取用户ID时获得NPE。也许用户没有登录,这就是ApplicationContext中没有相应对象的原因。