gpt4 book ai didi

java , Selenium ;编译代码时抛出异常

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:47 27 4
gpt4 key购买 nike

public class MainClass {

public static void main(String [] args) throws ClassNotFoundException{
//String[] xyz = {"Client1"};
List<XmlSuite> suites = new ArrayList<XmlSuite>();
XmlSuite suite=new XmlSuite();

suite.setName("Demo");

XmlTest test=new XmlTest(suite);
List<String> groups=new ArrayList<String>();
for(String arg:args){
groups.add(arg);
}
List<XmlClass> classes =new ArrayList<XmlClass>();
System.out.println(Class.forName("TrailAndTest.TestClass"));
classes.add(new XmlClass(Class.forName("TrailAndTest.TestClass")));

test.setXmlClasses(classes);
test.setIncludedGroups(groups);

suites.add(suite);

TestNG tng = new TestNG();
tng.setXmlSuites(suites);

tng.run();

}

}

在我的代码中,我编写的公共(public)类被定义为“public class Mainclass”,并且文件以名称 MainClass.java 保存当我尝试从命令提示符执行此代码时,我收到错误:

  1. C:\Selenium\Code\Test\src\TrailAndTest\Mainclass.java:13: class MainClass is pub lic, should be declared in a file named MainClass.java public class MainClass ^ 1 error

我执行的操作:

C:\Selenium\Code\Test>set path=%path%;"C:\Program Files\Java\jdk1.5.0_22\bin"

C:\Selenium\Code\Test>set
CLASSPATh="C:\Selenium\Code\Test\bin;C:\Selenium\Code\
Test\Jars\selenium-2.25.0\libs\commons-logging-1.1.1.jar;C:\Selenium\Eclipse\ecl
ipse-jee-indigo-win32-x86_64\eclipse\plugins\org.testng.eclipse_6.7.0.20120808_0
858\libtesting.jar;C:\Selenium\Eclipse\eclipse-jee-indigo-win32-x86_64\eclipse\p
lugins\org.eclipse.wb.runtime.lib_1.5.0.r37x201206111201\lib\cglib-nodep-2.2.jar
;C:\Selenium\ExternalJar\selenium-server-standalone-2.21.0.jar;"

C:\Selenium\Code\Test>javac -sourcepath "C:\Selenium\Code\Test\src"
"C:\Seleniu m\Code\Test\src\TrailAndTest\Mainclass.java" -d
"C:\Selenium\Code\Test\bin"
C:\Selenium\Code\Test\src\TrailAndTest\Mainclass.java:13: class
MainClass is pub lic, should be declared in a file named
MainClass.java public class MainClass
^ 1 error

C:\Selenium\Code\Test>

最佳答案

类名和文件名区分大小写。将文件重命名为“MainClass.java”并使用大写 C 以匹配类名。

关于 java , Selenium ;编译代码时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12103889/

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