- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
Java 新手...正在尝试运行示例应用程序。我包括了似乎与该问题相关的代码部分。如果需要,我可以发布整个测试应用程序。我
我正在尝试实现错误处理程序来处理应用程序通过应用程序运行的 htmlunit lib/test 解析目标网站时生成的 css 警告。
我不确定应该如何实现 MycssErrorHandler 类才能调用 ErrorHandler。我也不确定如何在代码/测试类的主体中实例化对象。
想法/评论/代码块会有所帮助..
谢谢!
编译时出现以下错误:
[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
====================================
测试代码块是:
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);
最佳答案
您的 MycssErrorHandler
类是抽象的
,这意味着您不能直接使用它。
一个抽象
类不能被实例化;它只能继承自。
您需要从类定义中删除 abstract
关键字。
一旦删除abstract
关键字,您还需要让您的类实现ErrorHandler
中的所有三个方法。界面。 (错误
、fatalError
和警告
)
关于javac 编译错误 - "...abstract; cannot be instantiated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2073156/
我刚遇到 MSVC(版本 12 更新 5)的问题: 如果模板函数具有通过 SFINAE 禁用的重载,则显式实例化模板函数会失败。但是,调用该函数(从而隐式实例化它)是有效的。 示例代码: #inclu
我正在阅读一本关于 DI 的书,该书总是谈论 DI 框架“实例化对象图”。为什么这样说而不是“实例化对象”? 最佳答案 对象图由保存彼此引用的对象组成。在这种情况下,图的另一个名称是网络。 如果 IO
一个类Customers实例化许多其他类(例如CustomersFromMysql、CustomersFromPostgeSQL),所有查询数据库都返回客户名称。现在,这些客户名称返回为例如 name
当我尝试调用 listenEventReducer 时,出现了这个奇怪的错误。该方法知道类型,但仍然不确定我哪里出错了。 import 'package:test/test.dart'; enum O
我正在尝试使用 org.hibernate.Interceptor.instantiate() 来拦截实例化(显然)并使用默认构造函数之外的构造函数手动实例化特定对象。如果要阅读此方法的 JavaDo
public class TestingClass { public static void main(String[] args) { int numberRooms = 6
为什么 C++ 以这样的方式创建,如果您有一个类 A 并声明一个类型 A 的数组,那么整个数组将填充使用该类的默认构造函数实例化的对象? 最佳答案 因为当您创建一个给定大小的数组时,数组的每个元素都必
考虑下面的例子 template struct S { A a; void foo() {} }; template void bar() { S *p = 0; } templat
Note that code is instantiated only for member functions that are called. For class templates, membe
当我尝试运行这段代码时: import java.io.*; import java.util.*; public class TwoColor { public static void ma
每当我尝试在 Unity 3D 中实例化粒子系统时,命令都会定位粒子但不会播放/运行动画。 这是我的代码 GameObject impactGO = Instantiate(impactEffect,
我使用以下代码在 verilog 中实例化二维内存 reg [15:0] data_pattern_even [3:0] = {16'hFFFF,16'hFFFF,16'hFFFF,16'hFFFF
假设我获得了我作为 String 创建的类的名称。 .如何使用该字符串中包含的名称实例化类?我知道它将派生自某个父类,但实际类会有所不同。 最佳答案 var instance : MyClass =
python 的 attrs 包提供了一种在实例化时验证传递的变量的简单方法 (example taken from attrs page): >>> @attr.s ... class C(obje
我收到 java 空指针异常。我无法解决它。我已在 testbase 类中初始化驱动程序,并希望在我的 Testing_TVO 类中使用相同的驱动程序 这是我的测试基类 public class te
我对 Java 编程还比较陌生,可能错过了一些明显的东西,所以请耐心等待。 我正在创建一个程序,该程序使用 Swing API 和 JDesktopPane 来创建 GUI。主屏幕上有一个按钮,上面写
python 的 attrs 包提供了一种在实例化时验证传递的变量的简单方法 (example taken from attrs page): >>> @attr.s ... class C(obje
C++ 模板中的“延迟实例化”是什么意思? 最佳答案 延迟实例化是指直到第一次使用对应的实体时才实例化模板。例如,您有一个模板化函数: template void YourFunction() {
当我阅读 spring 教程时,我发现了这样的内容: LocalChangeInterceptor localChangeInterceptor; localChangeInterceptor = n
我正在实现 unforgettable factory .一切正常,但有一件事:类(class)有时没有注册。 我认为关键部分是 Registrar::registered成员。如果使用它,“真正有趣
我是一名优秀的程序员,十分优秀!