I'm using the same version as in the tutorial. 24-SNAPSHOT. But for me ImageWorker.java#L548 is this: Object property = image.getProperty(NoDataContainer.GC_NODATA); so two lines above. I don't know why it's different. I'm using the pom given in the tutorial. So all the dependencies should be there. 
 
Debugger tells me after clicking the zoom to full extent button, that the image is still a WritableRenderedImageAdapter, but the field "theImage" within it is null. This was a BufferedImage when starting the application, so before clicking the button.
 
Interesting fact i just found out: If i resize the window after the exception, the image is rendered correctly again. All works like before pressing the button. Also "theImage" within the image is the BufferedImage again. It looks like it's a problem with the GUI, so maybe something within the Swing module causes the error?
 
Another thing i found out with debugger: The image is passed on from WMSCoverageReader at some point. The relevant part is this (Line 285-291):
 
        if (grid != null
                && grid.getGridGeometry().getGridRange2D().getWidth() == width
                && grid.getGridGeometry().getGridRange2D().getHeight() == height
                && grid.getEnvelope().equals(requestedEnvelope)) return grid;
        grid = getMap(reference(requestedEnvelope), width, height, backgroundColor);
        return grid;
 
when the bottom return is used, so at the start or after resize the getMap is executed again and everything is fine. When clicking the button, so the error will occur, it jumps inside the if and uses the grid that is present, but the image within is already with "theImage" field set to null. But i have no idea what causes this. Again, i did not change anything. Just using the tutorial code. Any idea what caues this grid to have this "theImage" value set to null? I guess the easy fix would be to always call getMap, but that can't be the solution.
 
<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <geotools.version>24-SNAPSHOT</geotools.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-shapefile</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-swing</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geotiff</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-image</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-wms</artifactId>
            <version>${geotools.version}</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>osgeo</id>
            <name>OSGeo Release Repository</name>
            <url>https://repo.osgeo.org/repository/release/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>osgeo-snapshot</id>
            <name>OSGeo Snapshot Repository</name>
            <url>https://repo.osgeo.org/repository/snapshot/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
 
 
Gesendet: Montag, 06. Juli 2020 um 22:53 Uhr
Von: "Jody Garnett" <jody.garn...@gmail.com>
An: "maca delic" <macade...@gmx.de>
Cc: "GeoTools Users" <geotools-gt2-users@lists.sourceforge.net>
Betreff: Re: [Geotools-gt2-users] Image tutorial not working
I am not sure yet, 
 
 
    public Range extractNoDataProperty(final RenderedImage image) {
        Object property = image.getProperty(NoDataContainer.GC_NODATA);
        if (property != null) {
            if (property instanceof NoDataContainer) {
                return ((NoDataContainer) property).getAsRange();
            } else if (property instanceof Double) {
                return RangeFactory.create((Double) property, (Double) property);
            }
        }
        return null;
    }
 
That line in bold does match up with javax.media.jai.RenderedImageAdapter.getProperty(RenderedImageAdapter.java:189) so I am going to ask what version of GeoTools you are running?
Looking at the source code for RenderedImageAdapter here (an open source fork) shows that getProperty is final, so chances are the image is null.
 
Can you step through with the debugger and check if the image is null?  I would ask that you check the tutorial dependencies to ensure you have everything needed for the wms client to work.
--
Jody Garnett
 
On Mon, 6 Jul 2020 at 09:42, maca delic <macade...@gmx.de> wrote:
Hi, i was going through the image tutroial (https://docs.geotools.org/latest/userguide/tutorial/raster/image.html). And just copy & pasted the wmslab class from the tutorial (from the extra things to try) and executed it. A swing window opens, which displays the wms, but as soon as i click the button to display the full extent of all layers without doing anything else i get a nullpointer:
 
java.lang.NullPointerException
    at javax.media.jai.RenderedImageAdapter.getProperty(RenderedImageAdapter.java:189)
    at org.geotools.image.ImageWorker.extractNoDataProperty(ImageWorker.java:548)
    at org.geotools.image.ImageWorker.setImage(ImageWorker.java:567)
    at org.geotools.image.ImageWorker.<init>(ImageWorker.java:510)
    at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRendererUtilities.affine(GridCoverageRendererUtilities.java:684)
    at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.affine(GridCoverageRenderer.java:515)
    at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.symbolize(GridCoverageRenderer.java:442)
    at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.renderImage(GridCoverageRenderer.java:761)
    at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.paint(GridCoverageRenderer.java:910)
    at org.geotools.renderer.lite.StreamingRenderer$RenderCoverageReaderRequest.execute(StreamingRenderer.java:3900)
    at org.geotools.renderer.lite.StreamingRenderer$PainterThread.run(StreamingRenderer.java:4011)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
 
Why does that happen? I tried multiple wms and it's the same for all. I didn't change the code, just copied from the tutorial.
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to