Using below code (which i mainly got from the GeoTools site) i get a NullPointer.
For reference, i used the OGC reference url for WMS 1.3
public static void main(String[] args) throws IOException, ServiceException {
String[] mList = {"http://metaspatial.net/cgi-bin/ogc-wms.xml"};
URL capabilitiesURL = WMSChooser.showChooseWMS(Arrays.asList(mList) );
if( capabilitiesURL == null ){
System.exit(0); // canceled
}
WebMapServer wms = new WebMapServer( capabilitiesURL );
List<org.geotools.data.ows.Layer> wmsLayers = WMSLayerChooser.showSelectLayer( wms );
if( wmsLayers == null ){
JOptionPane.showMessageDialog(null, "Could not connect - check url");
System.exit(0);
}
MapContent mapcontent = new MapContent();
mapcontent.setTitle( wms.getCapabilities().getService().getTitle() );
for( org.geotools.data.ows.Layer wmsLayer : wmsLayers ){
WMSLayer displayLayer = new WMSLayer(wms, wmsLayer );
mapcontent.addLayer(displayLayer);
}
// Now display the map
JMapFrame.showMap(mapcontent);
}
The stacktrace says this:
WARNING: Starting schema with ServiceExceptionReport element.
Exception in thread "main" java.lang.NullPointerException
at org.geotools.map.WMSCoverageReader.reference(WMSCoverageReader.java:432)
at org.geotools.map.WMSCoverageReader.updateBounds(WMSCoverageReader.java:402)
at org.geotools.map.WMSCoverageReader.addLayer(WMSCoverageReader.java:196)
at org.geotools.map.WMSCoverageReader.<init>(WMSCoverageReader.java:126)
at org.geotools.map.WMSLayer.<init>(WMSLayer.java:81)
at javagisviewer.JavaGisViewer.main(JavaGisViewer.java:50)
I'm using Netbeans 8.2 with Java 1.8u131 (not maven) I got rid of the next JAR files as per QuickStart ( http://docs.geotools.org/latest/userguide/tutorial/quickstart/netbeans.html ), i also removed the GDAL jar.
gt-arcgrid-18.1.jar
gt-arcsde-18.1.jar
gt-arcsde-common-18.1.jar
gt-epsg-hsql-18.1.jar
gt-epsg-oracle-18.1.jar
gt-epsg-postgresql-18.1.jar
gt-epsg-wkt-18.1.jar
gt-imageio-ext-gdal-18.1.jar
gt-jdbc-db2-18.1.jar
gt-jdbc-h2-18.1.jar
gt-jdbc-mysql-18.1.jar
gt-jdbc-oracle-18.1.jar
It looks like it's missing a Coordinate reference (srs/crs)?
I don't know where to go from here
For me, the code works perfectly! So you probably have a jar issue as you expect. This is why we recommend that GeoTools users use Maven so that this sort of issue doesn't arise.
Your problem is that you have removed all 4 of the epsg jars instead of just 3 of them as mentioned in the documentation. If you add gt-epsg-wkt-18.1.jar
back into your project all should be fine.