2012-08-24 141 views
1
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(); 

     } 

} 

在我的代碼時,我已經寫了公共類的定義「公共類Mainclass」,當我嘗試執行從命令提示符下這個代碼我得到錯誤文件保存名稱MainClass.java:Java,Selenium;拋出異常編譯代碼

由我進行
  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> 
+0

請檢查以備日後參考:http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title – Greg

+0

另請注意:當您*運行*代碼時發生異常。當你*編譯它時,你只能得到編譯器錯誤。 –

回答

1

類和文件名是區分大小寫的。使用大寫C將文件重命名爲「MainClass.java」以匹配類名稱。