2010-01-15 88 views
0

試圖創建一個導入另一個測試包的測試應用程序。javac編譯錯誤

應用程序中列出了測試,由於是編譯CMD和ERR ..

的文件都在同一目錄。我能夠編譯MyIncorrectnessListener.java和MycssErrorHandler.java,沒有警告/錯誤。

我想弄清楚err的原因是什麼>>> sjsu_classes.java:33:'。'預計< < < < <

任何指針/評論贊賞...

感謝

編譯CMD/ERR

[[email protected] parseapp2]# javac -Xlint -classpath '/opt/htmlunit/lib/ 
*:/parseapp2/' sjsu_classes.java sjsu_classes.java:33: '.' expected 
import MyIncorrectnessListener; 
          ^
sjsu_classes.java:33: ';' expected 
import MyIncorrectnessListener; 
          ^
sjsu_classes.java:34: class, interface, or enum expected 
import MycssErrorHandler; 
    ^

3 errors 
3 warnings 



/* 
//  sjsu_classes.java 
// 
//  function handles getting the data from the sjsu course page, and returns the course page/list 
//  for the given Alphabet letter. - handles ane letter at a time.. 
//  -the page is then returned to the calling routinne 
// 
//    input: 
//      args[0] - start url 
//      args[1] - term 
//      args[2] - dept 
// 
//    return: 
//      course page for the term/dept 
// 
*/ 
import java.io.IOException; 
import java.net.URL; 
import java.util.List; 
import java.util.Set; 

import org.apache.commons.httpclient.NameValuePair; 

import com.gargoylesoftware.htmlunit.*; 
import com.gargoylesoftware.htmlunit.html.*; 
import org.w3c.css.sac.ErrorHandler; 
import org.xml.sax.SAXParseException; 

//==my test packages 
import MyIncorrectnessListener; 
import MycssErrorHandler; 

public class sjsu_classes { 

    //public static void main(String[] args) throws Exception { 
    public void main(String[] args) throws Exception { 

      // Create and initialize WebClient object 
     WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3); 

      IncorrectnessListener ilisten = new MyIncorrectnessListener(); 
      ErrorHandler ierr = new MycssErrorHandler(); 
      webClient.setIncorrectnessListener(ilisten); 
      webClient.setCssErrorHandler(ierr); 
     webClient.setThrowExceptionOnScriptError(false); 
     webClient.setRefreshHandler(new RefreshHandler() { 
     public void handleRefresh(Page page, URL url, int arg) throws IOException { 
          //System.out.println("handleRefresh"); 
        } 

      }); 

      // visit the page, get the form, get the btn 
      String url_tmp; 
      String url; 
      String Term; 
      String Dept; 
      String tmp1; 
      String tmp2; 

      url_tmp="?FolderPath=PORTAL_ROOT_OBJECT.PA_HC_CLASS_SEARCH&amp;PortalActualURL=https%3a%2f%2fcmshr.sjsu.edu%2fpsc%2fHSJPRDF%2fEMPLOYEE%2fHSJPRD%2fc%2fCOMMUNITY_ACCESS.CLASS_SEARCH.GBL&amp;PortalRegistryName=EMPLOYEE&amp;PortalServletURI=https%3a%2f%2fcmshr.sjsu.edu%2fpsp%2fHSJPRDF%2f&amp;PortalURI=https%3a%2f%2fcmshr.sjsu.edu%2fpsc%2fHSJPRDF%2f&amp;PortalHostNode=HRMS&amp;NoCrumbs=yes"; 

      System.exit(0); 
    } 

}

===== ==================

MyIncorrectnessListener test package 
-------------------------------------------- 
/* 
//  MyIncorrectnessListener.java 
// 
//  function handles getting the data from the sjsu course page, and returns the course page/list 
//  for the given Alphabet letter. - handles ane letter at a time.. 
//  -the page is then returned to the calling routinne 
// 
//    input: 
//      args[0] - start url 
//      args[1] - term 
//      args[2] - dept 
// 
//    return: 
//      course page for the term/dept 
// 
*/ 
//==handle the warnings thrown from the js functions.. 

package MyIncorrectnessListener; 

import com.gargoylesoftware.htmlunit.*; 
import com.gargoylesoftware.htmlunit.html.*; 

//public static class MyIncorrectnessListener implements IncorrectnessListener 
public class MyIncorrectnessListener implements IncorrectnessListener 
{ 
    @Override 
public void notify(String arg0, Object arg1) 
{ 
    //System.err.println("Argument : " + arg0.toString() + ", Object :"); 
} 
} 

MycssErrorHandler test package 
-------------------------------- 
/* 
//  MycssErrorHandler.java 
// 
//  function handles getting the data from the sjsu course page, and returns the course page/list 
//  for the given Alphabet letter. - handles ane letter at a time.. 
//  -the page is then returned to the calling routinne 
// 
//    input: 
//      args[0] - start url 
//      args[1] - term 
//      args[2] - dept 
// 
//    return: 
//      course page for the term/dept 
// 
*/ 
package MycssErrorHandler; 

import org.w3c.css.sac.ErrorHandler; 
import org.xml.sax.SAXParseException; 
import com.gargoylesoftware.htmlunit.*; 
import com.gargoylesoftware.htmlunit.html.*; 

//==handle the warnings thrown from the js functions.. 
     //==handle the warnings thrown from the css functions.. 
//  public static class MycssErrorHandler implements DefaultCssErrorHandler 
//  public static class MycssErrorHandler implements ErrorHandler 
//  public class MycssErrorHandler implements ErrorHandler 
     public abstract class MycssErrorHandler implements ErrorHandler 
//  protected class MycssErrorHandler implements ErrorHandler 
     { 
     //@Override 
     public void notify(String arg0, Object arg1) 
     { 
      //System.err.println("Argument : " + arg0.toString() + ",Object : "); 
     } 
     //@Override 
       public void fatalError(SAXParseException ex) 
       { 
         //fatals.add(ex); 
       } 
     } 

回答

1

Java文件必須在一個符合他們包名的目錄,所以你必須把 MyIncorrectnessListener.java在名爲MyIncorrectnessListener,MycssErrorHandler.java在名爲MycssErrorHandler目錄目錄等等。

您可以將它們全部放在同一目錄中,但必須刪除文件中的'包'語句。

您遇到的錯誤是因爲您只在導入語句中提供包名稱。你應該從軟件包中導入一些特定的東西或者所有東西。將其更改爲

import MyIncorrectnessListener.MyIncorrectnessListener; 

import MyIncorrectnessListener.*; 

或者,如果你不把任何包文件,你不需要任何import語句。

相關問題