我有这样的条件:
try {
History history = requestHelper.getHistory();
if (!history.getInvoiceNo().equalsIgnoreCase("") || //String
!history.getCcEmail().equalsIgnoreCase("") || //String
!history.getHostAuthCode().equalsIgnoreCase("") || //String
!history.getMerchantCategory().equalsIgnoreCase(null) || //String
!history.getCcName().equalsIgnoreCase("") || //String
!history.getCcPhone().equalsIgnoreCase("") || //String
history.getBatchNo() != 0 || //int
!history.getIpAddress().equalsIgnoreCase("") || //String
!history.getTransactionStatus().equals(null)) { //char
System.out.println(": : : FAILED GET HISTORY, NO PARAMETER SET!");
requestHelper.getResultHelper().setLstHistoryTransaction(null);
else {
System.out.println(": : : SUCCESS GET HISTORY!");
/* some command */
}
} catch (Exception ex) {
System.out.println(": : : ERROR QUERYING HISTORY TO DATABASE");
ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我不填充该参数的任何变量时,为什么它会像这样得到错误:
10:07:35,238 INFO [STDOUT] :::错误查询历史到数据库
10:07:35,238 ERROR [STDERR] java.lang.NullPointerException
10:07:35,238错误[STDERR] at doku.edp.executors.ManageTransactionExecutorBean.findHistoryTransaction (ManageTransactionExecutorBean.java:411)10:07:35,238
错误[STDERR] at doku.edp.executors.ManageTransactionExecutorBean.execute(ManageTransactionExecutorBean.java:78)
10:07:35,239 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0 (本机方法)
10:07:35,239 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:07:35,239 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 25)
10:07:35,239 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
10:07:35,239 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget( MethodInvocation.java:122)10:07:35,239
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvoc)中的错误[STDERR] ation.java:111)10:07:35,239
ERROR [STDERR] at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
10:07:35,239 org.jboss.ejb3.interceptors中的ERROR [STDERR]. aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
10:07:35,239 ERROR [STDERR] at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)10:07:35,239 ERROR [STDERR ] at sun.reflect.GeneratedMethodAccessor402.invoke(Unknown Source)
10:07:35,239 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:07:35,239 ERROR [STDERR] at java.lang .reflect.Method.invoke(Method.java:597)
10:07:35,239错误[STDERR] at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
10:07:35,239 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
10:07:35,239 org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod的ERROR [STDERR](InvocationContextInterceptor.java:72)10:07:35,239
ERROR [STDERR] at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_613521570.invoke(
VerocationContextInterceptor_z_fillMethod_613521570.java ) 10:07:35,239 ERROR [STDERR ] org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
10:07:35,239 org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)中的ERROR [STDERR]
10:07:35,239 ERROR [STDERR] at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_613521570.invoke(
VerocationContextInterceptor_z_setup_613521570.java ) 10:07:35,239 org.jboss的ERROR [STDERR]. aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
10:07:35,239 ERROR [STDERR] at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
10:07:35,239 ERROR [STDERR ] org.jboss.aop.joinpoint.MethodInvocation.invoke Next(MethodInvocation.java:102)
10:07:35,239 org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)中的ERROR [STDERR]
我建议if像这样重写你的陈述:
if (!"".equals(history.getInvoiceNo()) || //String
!"".equals(history.getCcEmail()) || //String
!"".equals(history.getHostAuthCode()) || //String
history.getMerchantCategory() != null || //String
!"".equals(history.getCcName()) || //String
!"".equals(history.getCcPhone()) || //String
history.getBatchNo() != 0 || //int
!"".equals(history.getIpAddress()) || //String
history.getTransactionStatus() != null) {
Run Code Online (Sandbox Code Playgroud)
有没有在使用没有意义equalsIgnoreCase,当你比较空字符串,并有在不使用点equals比较时null.
| 归档时间: |
|
| 查看次数: |
182 次 |
| 最近记录: |