新來java ...試圖讓一個示例應用程序運行。我將包含與該問題相關的代碼部分。如果需要,我可以發佈整個測試應用程序。我javac編譯錯誤 - 「...抽象;不能被實例化」
我想實現錯誤處理程序來處理應用程序運行時通過htmlunit lib /測試解析目標網站時生成的css警告。
我不確定應該如何實現MycssErrorHandler類來調用ErrorHandler。我也不確定如何在代碼/測試類的主體中實例化對象。
想法/評論/代碼塊將有幫助..
謝謝!
我收到以下錯誤,當我編譯:
[[email protected] parseapp2]# javac -Xlint -classpath '/opt/htmlunit/lib/*:/parseapp2/' sjsu_classes.java
warning: [path] bad path element "/opt/htmlunit/lib/xml-apis.jar": no such file or directory
warning: [path] bad path element "/opt/htmlunit/lib/xercesImpl.jar": no such file or directory
warning: [path] bad path element "/opt/htmlunit/lib/serializer.jar": no such file or directory
sjsu_classes.java:92: sjsu_classes.MycssErrorHandler is abstract; cannot be instantiated
ErrorHandler ierr = new MycssErrorHandler();
^
1 error
3 warnings
====================================
測試代碼塊是:
import org.w3c.css.sac.ErrorHandler;
import com.gargoylesoftware.htmlunit.DefaultCssErrorHandler;
import org.xml.sax.SAXParseException;
public class sjsu_classes {
//==handle the warnings thrown from the js functions..
public static class MyIncorrectnessListener implements IncorrectnessListener
{
@Override
public void notify(String arg0, Object arg1)
{
//System.err.println("Argument : " + arg0.toString() + ", Object : ");
}
}
//==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);
}
}
//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.EXPLORER_7);
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
//WebClient webClient = new WebClient();
IncorrectnessListener ilisten = new MyIncorrectnessListener();
ErrorHandler ierr = new MycssErrorHandler();
webClient.setIncorrectnessListener(ilisten);
webClient.setCssErrorHandler(ierr);
你應該接受解答您的疑問。你也應該閱讀一本關於Java的好書,比如Core Java。 – SLaks 2010-01-15 16:42:39
嗨... 感謝您的回答....我看了很多線程試圖處理這個沒有運氣!因此,我所要做的就是基本上創建虛擬存根來覆蓋其他方法。 謝謝.. – 2010-01-15 22:34:09