2016-07-29 26 views
5

私は最近、GeoToolsでJDK 1_7でJAI-Javaの高度なイメージング1_1_2_01も使用していた最初のプログラムを開始しました。 GeoTiff Jarsを追加するまでうまくいきました。私はコードがjava.lang.NoClassDefFoundError:クラスjavax.media.jai.JAIを初期化できません

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ジャー下記の通りである

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)

次のエラーを発見した

JDK images jar

その他ジャー

Part1

part2

私はまた、GeoToolsのjarファイルのクラスパス変数を追加

classpath

編集:

私宰はGeoTools統合せずに取り組んでいるが、私は gt-geotiff-14.4.jarを追加するとき、それは矛盾 JAI-core-1.1.3.jarを追加しよう

私のJDK 1.7にはjai-core.jarがあります。だから私はJAI-core-1.1.3.jarとそれに関連するjarを削除しましたが、それでも私は同じエラーが出ます。

+0

完全なスタックトレースを追加できますか? – Jens

+0

質問の先頭に上にコピーされます。しかし、私は瓶が矛盾していた答えを見つけました。だからもっと答えの必要はありません。 –

答えて

3

は、最後にそれは私がGEOTIFF jai-core-1.1.3.jarjai-codec-1.1.3.jarjai-imageio-1.1.jarファイルを削除するときに働いて、コメントを追加jai-extのgt-utilityクラスファイル用の新しいクラスです。私はgithubからコピーして、自分のプロジェクトのsrcに追加しました。 gtユーティリティーが欠落していました。瓶も矛盾していた。

2

あなたのクラスパスに

+0

既に追加されています –

+0

@ParthTrivediあなたが追加したところ、あなたのプログラムの起動方法を表示 – Jens

+0

JDK 1.7が追加されたEclipseを使用しています、JAIがインストールされていますスナップショットはアクセス制限なしでjai jarsを表示し、 Xms512m -Xmx512m -XX:MaxPermSize = 512m 'このエラーが表示されます。 –

0

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)

+0

jai-1_1_2-lib-windows-i586-jre.exeとjai-1_1_2-lib-windows-i586-jdk.exe、私再インストールされ、彼らはジャーがJAIクラスの初期化のために来ているだけで、今このエラーだけで解決されたアクセス制限のためのエラーも表示されているように私の日食に正しく表示されます。 –

+0

すべての手順はそのサイトから行われます。また、JDKフォルダ全体とJREフォルダ全体に完全な権限が与えられていますが、まだエラーがあります。 –

+0

GeoTools 14.xはJDK1にも対応しています。7とjai-1_1_2-libもJDK 1.7用です。 –

関連する問題