NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
(... continuing since I clicked "Send" to soon) The NPE occurs because the 'ncfile.getLocation()' returns null My question is, is this supposed to work and am I doing something wrong? Or maybe this is not the way you are supposed to work with NetCDF -files that you want to modify the contents of? Den ons 7 apr. 2021 kl 16:33 skrev Andreas Imner <andreas.imner@xxxxxxxxx>: > Hi! > A am trying to use the Java NetCDF library to modify the data of a > variable in an existing NetCDF4 file. > > I use the 5.4.1 version of the Java library > I have version 4.7.4_2 of the netcdf C-library installed and it works > properly. > > The problem I get is that when opening the existing file for writing, a > NPE is thrown. > > My code looks something like this... > > NetcdfFormatWriter.Builder builder = > NetcdfFormatWriter.openExisting("/temp/input.nc").setFormat(NetcdfFileFormat.NETCDF4).setNewFile(false); > NetcdfFormatWriter writer = builder.build(); > > But when .build() is called an exception is thrown > > Exception in thread "main" java.lang.NullPointerException > at ucar.nc2.NetcdfFiles.canonicalizeUriString(NetcdfFiles.java:359) > at ucar.nc2.jni.netcdf.Nc4Iosp._open(Nc4Iosp.java:253) > at ucar.nc2.jni.netcdf.Nc4Iosp.openForWriting(Nc4Iosp.java:239) > at ucar.nc2.write.NetcdfFormatWriter.<init>(NetcdfFormatWriter.java:329) > at ucar.nc2.write.NetcdfFormatWriter.<init>(NetcdfFormatWriter.java:49) > at > ucar.nc2.write.NetcdfFormatWriter$Builder.build(NetcdfFormatWriter.java:261) > > Looking at the code in the class Nc4Iosp.java > > private void _open(RandomAccessFile raf, NetcdfFile ncfile, boolean readOnly) > throws IOException { > ... > String location = NetcdfFiles.canonicalizeUriString(ncfile.getLocation()); > > >
netcdf-java
archives: