gpt4 book ai didi

java - 带参数调用方法

转载 作者:行者123 更新时间:2023-11-28 23:19:47 25 4
gpt4 key购买 nike

我的反射有问题。

本质:类中有一堆方法。我觉得有必要这样(这里一切都很好):

invokingMethod = InstanceClass.getMethod(AMethodName, AArgumentTypes);

那我要调用它:

result = invokingMethod.invoke(AInstance, AArgumentObjects);

参数个数可以不同。这里只是调用授权方法,因此只有两个参数

方法签名:

public abstract long userLogin(java.lang.String,java.lang.String) 

内容 AArgumentsTypes:

enter image description here

内容 AArgumentObjects:

enter image description here

结果,我收到有关传递的参数类型错误的错误消息。

仅当您将所有参数显式传递给函数时才有效。或者我在调试菜单变量中使用 AArgumentObjects[1](如果我在代码中更改它,错误仍然存​​在):

enter image description here

在使用 AArgumentObjects[1] 从代码中调用之后:

放电:“java.lang.IllegalArgumentException” enter image description here

24-Jul-2017 14:21:08.444 SEVERE [http-nio-8081-exec-3] ru.nahodka.general.Reflection.TReflexiveClassUtils.invokeMethod java.lang.IllegalArgumentException: wrong number of arguments
24-Jul-2017 14:21:08.444 INFO [http-nio-8081-exec-3] org.directwebremoting.log.accessLog.writeExceptionToAccessLog Method execution failed:
ru.nahodka.Applications.WebApplication.TCustomizableWebApplicationAbstractBothPart$WebServiceMethodInvokedException: Не удалось произвести вызов функции UserLogin в интерфейсе ru.nahodka.Family.Constants.FamilyClientMainInterfaceConstants.FamilyIntf. Код ошибки rwsrProcedureSuccess.
at ru.nahodka.ISUpravlenie.Implementation.ClientPart.MainInterfaceServiceInvoker.ControlLowLevelMainFunctionalClass.UserLogin(ControlLowLevelMainFunctionalClass.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at ru.nahodka.general.Reflection.TReflexiveUtils.InvokeMethodWithParameters(TReflexiveUtils.java:729)
at ru.nahodka.ISUpravlenie.Implementation.ClientPart.AbstractFunctional.ControlHighLevelAbstractFunctionalClientClass.getLowLevelMethodInvokeResult(ControlHighLevelAbstractFunctionalClientClass.java:170)
at ru.nahodka.ISUpravlenie.Implementation.ClientPart.MainInterfaceServiceInvoker.ControlHighLevelMainFunctionalClass.UserLogin(ControlHighLevelMainFunctionalClass.java:208)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.directwebremoting.impl.CreatorModule$1.doFilter(CreatorModule.java:178)
at org.directwebremoting.impl.CreatorModule.executeMethod(CreatorModule.java:184)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:353)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:306)
at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:110)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:211)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:185)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

最佳答案

我是这样解决问题的,谢谢大家:

 result = invokingMethod.invoke(AInstance, ((Object[])AArgumentObjects[1]));

关于java - 带参数调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45278807/

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