java.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI
java.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI
我最近使用 GeoTools 开始了我的第一个程序,其中我还使用了 JAI-Java 高级成像 1_1_2_01 和 JDK 1_7。 在我添加 GeoTiff Jars 之前它工作正常。我发现以下错误
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI
at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:607)
at com.rgb.PixelExtractor.extract(PixelExtractor.java:55)
at com.rgb.RGBSpliter.main(RGBSpliter.java:136)
代码如下
public void extract(File f, String name, String date) throws Exception {
ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY
.createValue();
policy.setValue(OverviewPolicy.IGNORE);
// this will basically read 4 tiles worth of data at once from the disk...
ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
//gridsize.setValue(512 * 4 + "," + 512);
// Setting read type: use JAI ImageRead (true) or ImageReaders read methods (false)
ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
useJaiRead.setValue(true);
//reader.read(new GeneralParameterValue[] { policy, gridsize, useJaiRead });
// The line that throws error
GridCoverage2D image
= new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});
Rectangle2D bounds2D = image.getEnvelope2D().getBounds2D();
bounds2D.getCenterX();
// calculate zoom level for the image
GridGeometry2D geometry = image.getGridGeometry();
BufferedImage img = ImageIO.read(f);
// ColorModel colorModel = img.getColorModel(
WritableRaster raster = img.getRaster();
int numBands = raster.getNumBands();
int w = img.getWidth();
int h = img.getHeight();
outer:
for (int i = 0; i < w; i++) {//width...
for (int j = 0; j < h; j++) {
double[] latlon = geo(geometry, i, j);
double lat = latlon[0];
double lon = latlon[1];
Double s = 0d;
String originalBands = "";
for (int k = 0; k < numBands; k++) {
double d = raster.getSampleDouble(i, j, k);
originalBands += d + ",";
s += d;
}
originalBands = originalBands.substring(0, originalBands.length() - 1);
if (s.compareTo(0d) == 0) {
continue;
}
String geoHash = GeohashUtils.encodeLatLon(lat, lon);
//here do something with the bands, lat, long, geohash, etc....
}
}
}
private static double[] geo(GridGeometry2D geometry, int x, int y) throws Exception {
//int zoomlevel = 1;
Envelope2D pixelEnvelop = geometry.gridToWorld(new GridEnvelope2D(x, y, 1, 1));
// pixelEnvelop.getCoordinateReferenceSystem().getName().getCodeSpace();
return new double[]{pixelEnvelop.getCenterY(), pixelEnvelop.getCenterX()};
}
}
JDK 罐子
其他罐子
我还为 GeoTools jar 添加了类路径变量
编辑:
我的 jai 在没有 GeoTools Integration 的情况下工作,但是当我添加 gt-geotiff-14.4.jar
时,它会尝试添加 JAI-core-1.1.3.jar
,这与我的 JDK 1.7 中的 jai-core.jar
冲突。所以我删除了 JAI-core-1.1.3.jar
和相关的罐子,但它仍然给我同样的错误。
您必须将 jai-core.jar
添加到您的类路径
JAI请关注GeoTools setup instructions
:
Java Advanced Imaging Java Advanced Imaging is an image processing
library allowing you to form chains of operations to process rasters
in a manner similar to functional programming.
References:
http://java.net/projects/jai-core Download this Version of JAI
Java Advanced Imaging API 1.1.3 At the time of writing Oracle is
migrating java projects around - try the following:
http://download.java.net/media/jai/builds/release/1_1_3/
http://download.java.net/media/jai/builds/release/1_1_3/INSTALL.html
Download JAI for your JDK by clicking on the link for your platform:
Example: jai-1_1_3-lib-windows-i586-jdk.exe
Use the one click installer to install JAI into your JDK
Download JAI for your JRE by clicking on the link for your platform:
Example: jai-1_1_3-lib-windows-i586-jre.exe
Use the one click installer to install JAI into your JRE
(If you are working on linux you will of course need to choose the
appropriate download)
当我删除 Geotiff jai-core-1.1.3.jar
、jai-codec-1.1.3.jar
和 jai-imageio-1.1.jar
文件并为 jai-ext 的 gt-utility [=18 添加新的 class 时,它终于起作用了=] 文件。我刚刚从 github 复制并添加到我的项目的 src。gt-utility 是缺少的那个。罐子也很矛盾。
我最近使用 GeoTools 开始了我的第一个程序,其中我还使用了 JAI-Java 高级成像 1_1_2_01 和 JDK 1_7。 在我添加 GeoTiff Jars 之前它工作正常。我发现以下错误
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:607) at com.rgb.PixelExtractor.extract(PixelExtractor.java:55) at com.rgb.RGBSpliter.main(RGBSpliter.java:136)
代码如下
public void extract(File f, String name, String date) throws Exception {
ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY
.createValue();
policy.setValue(OverviewPolicy.IGNORE);
// this will basically read 4 tiles worth of data at once from the disk...
ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
//gridsize.setValue(512 * 4 + "," + 512);
// Setting read type: use JAI ImageRead (true) or ImageReaders read methods (false)
ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
useJaiRead.setValue(true);
//reader.read(new GeneralParameterValue[] { policy, gridsize, useJaiRead });
// The line that throws error
GridCoverage2D image
= new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});
Rectangle2D bounds2D = image.getEnvelope2D().getBounds2D();
bounds2D.getCenterX();
// calculate zoom level for the image
GridGeometry2D geometry = image.getGridGeometry();
BufferedImage img = ImageIO.read(f);
// ColorModel colorModel = img.getColorModel(
WritableRaster raster = img.getRaster();
int numBands = raster.getNumBands();
int w = img.getWidth();
int h = img.getHeight();
outer:
for (int i = 0; i < w; i++) {//width...
for (int j = 0; j < h; j++) {
double[] latlon = geo(geometry, i, j);
double lat = latlon[0];
double lon = latlon[1];
Double s = 0d;
String originalBands = "";
for (int k = 0; k < numBands; k++) {
double d = raster.getSampleDouble(i, j, k);
originalBands += d + ",";
s += d;
}
originalBands = originalBands.substring(0, originalBands.length() - 1);
if (s.compareTo(0d) == 0) {
continue;
}
String geoHash = GeohashUtils.encodeLatLon(lat, lon);
//here do something with the bands, lat, long, geohash, etc....
}
}
}
private static double[] geo(GridGeometry2D geometry, int x, int y) throws Exception {
//int zoomlevel = 1;
Envelope2D pixelEnvelop = geometry.gridToWorld(new GridEnvelope2D(x, y, 1, 1));
// pixelEnvelop.getCoordinateReferenceSystem().getName().getCodeSpace();
return new double[]{pixelEnvelop.getCenterY(), pixelEnvelop.getCenterX()};
}
}
JDK 罐子
其他罐子
我还为 GeoTools jar 添加了类路径变量
编辑:
我的 jai 在没有 GeoTools Integration 的情况下工作,但是当我添加 gt-geotiff-14.4.jar
时,它会尝试添加 JAI-core-1.1.3.jar
,这与我的 JDK 1.7 中的 jai-core.jar
冲突。所以我删除了 JAI-core-1.1.3.jar
和相关的罐子,但它仍然给我同样的错误。
您必须将 jai-core.jar
添加到您的类路径
JAI请关注GeoTools setup instructions :
Java Advanced Imaging Java Advanced Imaging is an image processing library allowing you to form chains of operations to process rasters in a manner similar to functional programming.
References:
http://java.net/projects/jai-core Download this Version of JAI
Java Advanced Imaging API 1.1.3 At the time of writing Oracle is migrating java projects around - try the following:
http://download.java.net/media/jai/builds/release/1_1_3/ http://download.java.net/media/jai/builds/release/1_1_3/INSTALL.html Download JAI for your JDK by clicking on the link for your platform:
Example: jai-1_1_3-lib-windows-i586-jdk.exe
Use the one click installer to install JAI into your JDK
Download JAI for your JRE by clicking on the link for your platform:
Example: jai-1_1_3-lib-windows-i586-jre.exe
Use the one click installer to install JAI into your JRE
(If you are working on linux you will of course need to choose the appropriate download)
当我删除 Geotiff jai-core-1.1.3.jar
、jai-codec-1.1.3.jar
和 jai-imageio-1.1.jar
文件并为 jai-ext 的 gt-utility [=18 添加新的 class 时,它终于起作用了=] 文件。我刚刚从 github 复制并添加到我的项目的 src。gt-utility 是缺少的那个。罐子也很矛盾。