java.lang.NoClassDefFoundError:无法初始化类javax.media.jai.JAI [英] java.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI
问题描述
我最近开始使用GeoTools开始我的第一个程序,其中我也使用JAI-Java Advanced Imaging 1_1_2_01和JDK 1_7。 在添加GeoTiff Jars 之前一切正常。我发现以下错误
线程main中的异常java.lang.NoClassDefFoundError:无法初始化类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);
//这基本上可以从磁盘上一次读取4个瓦片的数据...
ParameterValue< String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
//gridsize.setValue(512 * 4 +,+ 512);
//设置读取类型:使用JAI ImageRead(true)或ImageReaders读取方法(false)
ParameterValue< Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
useJaiRead.setValue(true);
//rereader.read(new GeneralParameterValue [] {policy,gridsize,useJaiRead});
//抛出错误的行
GridCoverage2D image
= new GeoTiffReader(f).read(new GeneralParameterValue [] {policy,gridsize,useJaiRead});
Rectangle2D bounds2D = image.getEnvelope2D()。getBounds2D();
bounds2D.getCenterX();
//计算图像的缩放级别
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);
//这里用band,lat,long,geohash做一些事情等等....
}
}
}
private static double [] geo(GridGeometry2D geometry,int x,int y)抛出异常{
/ / int zoomlevel = 1;
Envelope2D pixelEnvelop = geometry.gridToWorld(new GridEnvelope2D(x,y,1,1));
// pixelEnvelop.getCoordinateReferenceSystem()。getName()。getCodeSpace();
返回new double [] {pixelEnvelop.getCenterY(),pixelEnvelop.getCenterX()};
}
}
JDK Jars
其他罐子
我还为GeoTools jar添加了classpath变量
<编辑:
我的jai在没有GeoTools Integration的情况下工作,但当我添加 gt-geotiff-14.4.jar
它试图添加 JAI-core-1.1.3.jar
哪些冲突机智h jai-core.jar
在我的JDK 1.7中。所以我删除了 JAI-core-1.1.3.jar
和相关的jar,但它仍然给我同样的错误。
最后,当我删除Geotiff时,它工作了 jai-core-1.1.3.jar
, jai-codec -1.1.3.jar
和 jai-imageio-1.1.jar
文件并为jai-ext的 gt-utility 类文件。我刚刚从github复制并添加到我项目的src。 gt-utility 是缺少的那个。这些罐子也很矛盾。
I recently started my first program with GeoTools in which i was also using JAI- Java Advanced Imaging 1_1_2_01 with JDK 1_7. It worked fine until I added GeoTiff Jars. I found following error
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)
The Code is as below
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 Jars
Other Jars
I also added classpath variable for GeoTools jars
Edit:
My jai is working without GeoTools Integration, but when I add gt-geotiff-14.4.jar
it try to add JAI-core-1.1.3.jar
which conflicts with jai-core.jar
in my JDK 1.7. So I removed JAI-core-1.1.3.jar
and related jars but still it gives me same error.
Finally it worked when I removed Geotiff jai-core-1.1.3.jar
,jai-codec-1.1.3.jar
and jai-imageio-1.1.jar
files and added new class for jai-ext's gt-utility class files. I just copied from github and added to src of my project.gt-utility was the one which was missing. The jars were conflicting too.
这篇关于java.lang.NoClassDefFoundError:无法初始化类javax.media.jai.JAI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!