我正在尝试编写一个代码来使用Web服务: http : //www.webservicex.net/ws/WSDetails.aspx?CATID = 12&WSID = 64
我使用了Axis2的WSDL2Java.bat工具并生成了两个Java文件:
GeoIPServiceStub.java GeoIPServiceCallbackHandler.java我已将这些以及轴'lib'文件夹导入到我的项目中。
这是我正在使用的代码:
GeoIPServiceStub stub = new GeoIPServiceStub(); GetGeoIP geoIP = new GetGeoIP(); geoIP.setIPAddress("X.X.X.X"); GetGeoIPResponse reponse = stub.getGeoIP(geoIP);当我尝试运行它时,它会抛出一个InstantiationError 。
提前谢谢了!
I am trying to write a code to consume a web service found at: http://www.webservicex.net/ws/WSDetails.aspx?CATID=12&WSID=64
I've used Axis2's WSDL2Java.bat tool and had two Java files generated:
GeoIPServiceStub.java GeoIPServiceCallbackHandler.javaI've imported these, as well as the axis 'lib' folder into my project.
This is the code I'm using:
GeoIPServiceStub stub = new GeoIPServiceStub(); GetGeoIP geoIP = new GetGeoIP(); geoIP.setIPAddress("X.X.X.X"); GetGeoIPResponse reponse = stub.getGeoIP(geoIP);When I try running it, it throws an InstantiationError.
Many thanks in advance!
最满意答案
您正在尝试实例化抽象类或接口。 这就是抛出InstantiationError的原因。
根据文档,它陈述如下
公共类InstantiationError扩展了IncompatibleClassChangeError
当应用程序尝试使用Java新构造来实例化抽象类或接口时抛出。通常,编译器会捕获此错误; 如果类的定义不兼容地更改,则此错误只能在运行时发生。
you are trying to instantiate an abstract class or interface. that's why InstantiationError is thrown.
As per the docs, it is stated as follows
public class InstantiationError extends IncompatibleClassChangeError
Thrown when an application tries to use the Java new construct to instantiate an abstract class or an interface.Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
更多推荐
发布评论