gpt4 book ai didi

javac - javac编译错误

转载 作者:行者123 更新时间:2023-12-02 10:55:47 25 4
gpt4 key购买 nike

尝试创建一个导入另一个测试包的测试应用。

列出了测试应用程序,以及编译cmd和err。

这些文件都在同一目录中。我能够在没有警告/错误的情况下编译MyIncorrectnessListener.java和MycssErrorHandler.java。

我试图找出导致错误的原因>>> sjsu_classes.java:33:'。预期<<<<<

任何指针/评论表示赞赏...

谢谢

编译cmd/err

[root@toshiba 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);
}
}

最佳答案

您的Java文件必须位于与其包名称匹配的目录中,因此您必须放置
MyIncorrectnessListener.java位于名为MyIncorrectnessListener的目录中,MycssErrorHandler.java位于名为MycssErrorHandler的目录中,依此类推。

您可以将它们全部放在同一目录中,但是必须删除文件中的“package”语句。

您收到的错误是因为您只在import语句中给出了包名。您应该从包中导入特定的内容或所有内容。更改为

import MyIncorrectnessListener.MyIncorrectnessListener;

要么
import MyIncorrectnessListener.*;

或者,如果您不将文件放在任何包中,则不需要任何导入语句。

关于javac - javac编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2075363/

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