Domanda

I am using Eclipse on Windows XP. I downloaded the GeoTools 2.7.4-bin.zip file and started to add some .jar files to my project. The particularity of my project is that this is an Android one.

I am developing an Android application that would allow me to show on a map (google map) some features (points but not only) so i tried to use GeoTools to do that.But Android is not supporting Swings. My code is

/*code i m using */

package info.ipower.geotools;

import java.io.File;

import org.geotools.data.FileDataStore;

import org.geotools.data.FileDataStoreFinder;

import org.geotools.data.simple.SimpleFeatureSource;

import org.geotools.map.FeatureLayer;

import org.geotools.map.Layer;

import org.geotools.map.MapContent;

import org.geotools.styling.SLD;

import org.geotools.styling.Style;

import org.geotools.swing.JMapFrame;

import org.geotools.swing.data.JFileDataStoreChooser;


/**
 * Prompts the user for a shapefile and displays the contents on the screen in a map frame.
 * <p>
 * This is the GeoTools MapApplication application used in documentationa and tutorials. *
 */

public class GeoMap{

    /**
     * GeoTools MapApplication demo application. Prompts the user for a shapefile and displays its
     * contents on the screen in a map frame
     */
    public static void main(String[] args) throws Exception {
        // display a data store file chooser dialog for shapefiles
        File file = JFileDataStoreChooser.showOpenFile("shp", null);
        if (file == null) {
            return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();

        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        map.setTitle("MapApplication");

        Style style = SLD.createSimpleStyle(featureSource.getSchema());
        Layer layer = new FeatureLayer(featureSource, style);
        map.addLayer(layer);

        // Now display the map
        JMapFrame.showMap(map);
    }

}

But it giving me following errors in eclipse

-The method showOpenFile(String, Component) from the type JFileDataStoreChooser refers to the missing type Component

  • The type java.awt.Component cannot be resolved. It is indirectly referenced from required .class files
  • The type java.awt.HeadlessException cannot be resolved. It is indirectly referenced from required .class files
  • The type javax.swing.JFileChooser cannot be resolved. It is indirectly referenced from required .class files
  • The method showMap(MapContext) in the type JMapFrame is not applicable for the arguments (MapContent)
  • The type javax.swing.JFrame cannot be resolved. It is indirectly referenced from required .class files Please any one help me to resolve these errors
È stato utile?

Soluzione

Unfortunately Swing is not implemented on Android, so you are out of luck. In fact Oracle and Google just fought a big legal battle that was partially about this. I'm pretty sure that porting any serious Swing app or library to Android is a major effort: almost a rewrite from scratch.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top