Javac compile error - "... abstract, cannot be an instance"

New in java ... Trying to get a sample application to run. I am including a section of code that seems to be relevant to the problem. I can publish the entire test application if necessary. I

I am trying to implement an error handler to handle css alerts that are generated when an application parses target sites using the htmlunit lib / test that runs in the application.

I'm not sure exactly how the MycssErrorHandler class should be implemented to call ErrorHandler. I'm also not quite sure how to instantiate the object in the main body of the code / test class.

Thoughts / comments / code snippets would be helpful.

Thank!

When compiling, I get the following error:

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

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

Test code block:

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); 
+3
2

MycssErrorHandler abstract, , .

abstract; .

abstract .

abstract, ErrorHandler, (error, fatalError warning)

+3

, MycssErrorHandler . , . abstract, , MycssErrorHandler.

( MycssErrorHandler ? :))

+1

Source: https://habr.com/ru/post/1728652/


All Articles