javac compile error - "...abstract; cannot be instantiated"

java

Solution

Your `MycssErrorHandler` class is `abstract`, meaning that you can't use it directly.

An `abstract` class cannot be instantiated; it can only be inherited from.

You need to remove the `abstract` keyword from the class definition.

Once you remove the `abstract` keyword, you will also need to make your class implement all three method in the `ErrorHandler` interface. (`error`, `fatalError`, and `warning`)

Problem

New to java... Trying to get a sample app to run. I'm including the section of code that appears to be relevant to the issue. I can post the entire test app if needed. I I'm trying to implement the errorhandler to handle the css warnings that are generated when the app is parsing targeted websites via the htmlunit lib/test that the app runs. I'm not sure exactly how the MycssErrorHandler class should be implemented in order to invoke the ErrorHandler. I'm also not exactly sure how to instantiate the object in the main body of the code/test class. Thoughts/Comments/Code chunks would be helpful.. Thanks! I'm getting the following error when I compile: ``` [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 ==================================== ``` The test code chunk is: ``` 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); ```

Original source