2016-07-29 15 views
5

प्रारंभ नहीं किया जा सका मैंने हाल ही में जियोटूल के साथ अपना पहला कार्यक्रम शुरू किया जिसमें मैं जेडी-जावा उन्नत इमेजिंग 1_1_2_01 का उपयोग जेडीके 1_7 के साथ भी कर रहा था। यह ठीक काम करता है जब तक कि मैंने जियोटीफ जार जोड़ा। मैं निम्नलिखित त्रुटि पाईjava.lang.NoClassDefFoundError: क्लास javax.media.jai.JAI

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 जार नीचे के रूप में है

JDK images jar

अन्य जार

Part1

part2

मैं भी GeoTools जार के लिए classpath चर जोड़े

classpath

संपादित करें:

मेरे जय GeoTools एकता के बिना काम कर रहा है, लेकिन जब मैं gt-geotiff-14.4.jar जोड़ने यह JAI-core-1.1.3.jar जो विरोध करता है जोड़ने की कोशिश मेरे जेडीके 1.7 में jai-core.jar के साथ। इसलिए मैंने JAI-core-1.1.3.jar और संबंधित जार हटा दिए लेकिन फिर भी यह मुझे एक ही त्रुटि देता है।

+0

क्या आप पूरा स्टैकट्र्रेस जोड़ सकते हैं? – Jens

+0

इसे प्रश्न की शुरुआत में ऊपर कॉपी किया गया है। लेकिन मुझे जवाब मिला कि जार विवादित थे। तो अधिक उत्तरों की कोई ज़रूरत नहीं है। –

उत्तर

3

अंत में यह काम किया जब मैं GeoTiff jai-core-1.1.3.jar, jai-codec-1.1.3.jar और jai-imageio-1.1.jar फ़ाइलें और जोड़ा हटाया जय-एक्सटी के gt-utility क्लास फाइलों के लिए नई कक्षा। मैंने बस जिथब से कॉपी किया और मेरी परियोजना के स्रोत में जोड़ा। gt-utility वह था जो गायब था। जार भी विरोधाभासी थे।

2

आप अपने classpath को jai-core.jar जोड़ने के लिए

+0

यह पहले से जोड़ा गया है –

+0

@ पार्थ त्रिवेदी जहां आपने जोड़ा है, दिखाएं कि आप अपना प्रोग्राम कैसे शुरू करते हैं – Jens

+0

मैं ग्रहण का उपयोग कर रहा हूं जिसमें जेडीके 1.7 जोड़ा गया है, जेएआई स्थापित स्नैपशॉट जय जार को बिना किसी एक्सेस प्रतिबंध के दिखाता है और मैंने मेमोरी विकल्प भी सेट किए हैं '- Xms512m -Xmx512m -XX: MaxPermSize = 512m 'अब यह मुझे यह त्रुटि देता है। –

0

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

जय -1_1_2-lib-windows-i586-jre.exe और jai-1_1_2-lib-windows-i586-jdk.exe, I पुनर्स्थापित किया गया है और वे मेरे ग्रहण में सही ढंग से दिखाई दे रहे हैं क्योंकि जार दिखा रहे हैं कि एक्सेस प्रतिबंध के लिए भी त्रुटि हल हो गई है, अब केवल यह त्रुटि जेएआई कक्षा के आरंभ के लिए आ रही है। –

+0

उस साइट से सभी चरणों का पालन किया जाता है, पूरे जेडीके फ़ोल्डर के साथ-साथ जेआरई फ़ोल्डर को भी पूर्ण अनुमति दी जाती है, फिर भी त्रुटि होती है। –

+0

जियोटूल 14.x जेडीके 1 के लिए भी है।7 और जय -1_1_2-lib भी जेडीके 1.7 के लिए है। –

संबंधित मुद्दे