Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获得;NOSuchMethodException“;在Java中使用Excel执行时的反射_Java_Reflection_Apache Poi - Fatal编程技术网

获得;NOSuchMethodException“;在Java中使用Excel执行时的反射

获得;NOSuchMethodException“;在Java中使用Excel执行时的反射,java,reflection,apache-poi,Java,Reflection,Apache Poi,我尝试使用Java反射和Microsoft Excel执行Selenium代码,以实现关键字驱动的框架。但是代码执行时没有任何问题,但在结果的末尾得到了“NoSuchMethodException”。有谁能帮忙吗。我不熟悉“Java反射”和“关键字驱动框架” 我不知道为什么它会继续执行,即使类名不匹配 似乎MethodName是一个空字符串。我确定,它正在执行我在excel工作表中添加的所有方法。。我想的是它仍然在执行空行…哦,我明白了,是不是单元格的末尾包含了一些空格?如果是这样,请尝试将tr

我尝试使用Java反射和Microsoft Excel执行Selenium代码,以实现关键字驱动的框架。但是代码执行时没有任何问题,但在结果的末尾得到了“NoSuchMethodException”。有谁能帮忙吗。我不熟悉“Java反射”和“关键字驱动框架”

我不知道为什么它会继续执行,即使类名不匹配


似乎
MethodName
是一个空字符串。我确定,它正在执行我在excel工作表中添加的所有方法。。我想的是它仍然在执行空行…哦,我明白了,是不是单元格的末尾包含了一些空格?如果是这样,请尝试将
trim()
添加到比较中的
getStringCellValue
。确定。。我会试着让你知道:)它不起作用。。我添加了修剪,但它不起作用
 for(int Tests=1;Tests<TestData.sheet.getLastRowNum()+1;Tests++){

      if(this.getClass().getSimpleName().contains(TestData.sheet.getRow(Tests).getCell(0).getStringCellValue()))
        { 
                String MethodName=TestData.sheet.getRow(Tests).getCell(2).getStringCellValue();
            try{    
                Method method=FunctionLibrary.class.getMethod(MethodName,String.class,String.class,String.class);
                method.invoke(lib,TestData.sheet.getRow(Tests).getCell(5).getStringCellValue(),TestData.sheet.getRow(Tests).getCell(6).getStringCellValue(),TestData.sheet.getRow(Tests).getCell(4).getStringCellValue());
            }catch(InvocationTargetException | NoSuchMethodException e){
                e.printStackTrace();
            }
          }
        }
java.lang.NoSuchMethodException: lib.FunctionLibrary.(java.lang.String, java.lang.String, java.lang.String)
    at java.lang.Class.getMethod(Unknown Source)
    at testCaseWithKeywordFramework.TestCase1_Login.Login(TestCase1_Login.java:36)
    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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:776)
    at org.testng.TestRunner.run(TestRunner.java:634)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
    at org.testng.SuiteRunner.run(SuiteRunner.java:334)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
    at org.testng.TestNG.runSuites(TestNG.java:1161)
    at org.testng.TestNG.run(TestNG.java:1129)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
java.lang.NoSuchMethodException: lib.FunctionLibrary.(java.lang.String, java.lang.String, java.lang.String)
    at java.lang.Class.getMethod(Unknown Source)
    at testCaseWithKeywordFramework.TestCase1_Login.Login(TestCase1_Login.java:36)
    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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:776)
    at org.testng.TestRunner.run(TestRunner.java:634)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
    at org.testng.SuiteRunner.run(SuiteRunner.java:334)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
    at org.testng.TestNG.runSuites(TestNG.java:1161)
    at org.testng.TestNG.run(TestNG.java:1129)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)