hi, all
i am new to geotools. i am trying the shapefile reading programe on the
website. but it got problem when running it.
problem is: java.lang.NullPointerException!!!

the code is shown below. i think problem is in this line: "DataStore
dataStore = DataStoreFinder.getDataStore( connect );". please help me about
it. thanks a lot~~~~


//package org.geotools.demo.example;

import java.io.File;
import java.util.Map;
import java.util.HashMap;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;

import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.Feature;
import com.vividsolutions.jts.geom.Geometry;
import org.geotools.data.shapefile.*;
import org.geotools.data.shapefile.shp.*;
import org.geotools.data.shapefile.dbf.*;


//import org.geotools.factory.GeoTools;

public class readDATA
{
    public static void main( String[] args )
    {
        System.out.println( "Hello GeoTools " );

        try {

            //if( args.length != 1 ) System.exit(1);
            File file = new File( "bc_hospitals.shp" );
            if( !file.exists() ) System.exit(1);

            Map connect = new HashMap();
            connect.put( "url", file.toURL() );
            System.out.println(file.toURL().toString());

            DataStore dataStore = DataStoreFinder.getDataStore( connect );
            String[] typeNames = dataStore.getTypeNames();
            String typeName = typeNames[0];
 

            System.out.println( "Reading content "+ typeName );

            FeatureSource featureSource = dataStore.getFeatureSource(
typeName );
            FeatureCollection collection = featureSource.getFeatures();
            FeatureIterator iterator = collection.features();
            int length = 0;
            try {
                while( iterator.hasNext() ){
                    Feature feature = iterator.next();
                    Geometry geometry = feature.getDefaultGeometry();
                    length += geometry.getLength();
                }
            }
            finally {
                iterator.close();
            }
            System.out.println( "Total length "+length );

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
-- 
View this message in context: 
http://www.nabble.com/Problem-of-reading-shapefile-tf4666238.html#a13329516
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to