gpt4 book ai didi

android - GCM服务器java实现空指针异常

转载 作者:行者123 更新时间:2023-11-29 01:42:23 24 4
gpt4 key购买 nike

这是我的服务器代码 fragment

        Result result=null;
Sender sender = new Sender(SENDER_ID);
Message messages = new Message.Builder().timeToLive(30)
.delayWhileIdle(true).addData(MESSAGE_KEY, message).build();
System.out.println("regId: " + to);
try {
result = sender.send(messages, to, 5);
String error = result.getErrorCodeName();
System.out.println("Broadcast failure: " + error);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

登录目录:

java.lang.NullPointerException
at java.net.URLEncoder.encode(Unknown Source)
at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:166)
at com.google.android.gcm.server.Sender.send(Sender.java:121)
at com.punchit.controllers.SendTextNotification.send(SendTextNotification.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

所有变量都被正确赋值,没有变量为空看了很多网站,也没找到解决办法。甚至尝试更改 jar 文件任何建议都会很有帮助谢谢

最佳答案

您在这一行(Sender.java,第 166 行)得到异常:

addParameter(body, key, URLEncoder.encode(value, UTF8));

因此我假设您下面的 message 变量为空(因为这是您传递的唯一值):

Message messages = new Message.Builder().timeToLive(30)
.delayWhileIdle(true).addData(MESSAGE_KEY, message).build();

关于android - GCM服务器java实现空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23682247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com