实例化地理IP服务时出现问题



我使用的代码与我在网上找到的代码非常相似,但是我收到错误"无法实例化GeoIPService类型"。我在这里的另一个问题中发现了同样的问题,但从未得到解答。

import net.webservicex.www.GeoIP;
import net.webservicex.www.GeoIPService;
import net.webservicex.www.GeoIPServiceSoap;;
public class CountryFinder
{
    public static void main(String[] args)
    {
        GeoIPService service = new GeoIPService();  // "Cannot instaniate the type GeoServiceIP"
        GeoIPServiceSoap port = service.getGeoIPServiceSoap();
        System.out.print(port.getGeoIP("1.1.1.1").getCountryName());
    }
}       

更新:对于使用相同类的任何人,该问题已通过实例化GeoIPServiceLocator而不是GeoIPService来解决。

GeoIPService是一个

接口,而不是一个类,因此你必须实例化它的实现,而不是接口本身。

不對: GeoIPService service = new GeoIPService();

正确: GeoIPService service = new ClassThatImplementsGeoIPService();

最新更新