Thanks Jody.

 

I have already added a layer but the problem is that I can't even get it in
the layer list panel or in the Map Object Here is my code..

 

  File file = new
File("C:\\Users\\fodeh\\Desktop\\Parcels\\Parcels_Nab_Ram_02.shp");//JFileDa
taStoreChooser.showOpenFile("shp", null);

        if (file == null) {

            return;

        }

 

        FileDataStore store = FileDataStoreFinder.getDataStore(file);

        featureSource = store.getFeatureSource();

        setGeometry(featureSource);

        // CachingFeatureSource cache = new
CachingFeatureSource(featureSource);

 

        // Create a map context and add our shapefile to it

        StyleClass sClass=new StyleClass();

        Style style = sClass.createStyle(file, featureSource);

 

 

        //map.addLayer(featureSource, style);

        MapContext map = new DefaultMapContext();

        map.addLayer(featureSource, style);

 

        // Now display the map

        //Map.showMap(map);

        jMap = Map.getMapObj(map);

 

        jMap.showMap(map);

 

 

did you find any thing wrong?

 

Thanks

feras

 

From: Jody Garnett [mailto:[email protected]] 
Sent: Friday, September 03, 2010 4:47 PM
To: Feras Odeh
Cc: [email protected]
Subject: Re: [Geotools-gt2-users] null pointer exception while trying to set
layer style

 

You may need to add the layer first? There is a chance the getLayers() array
is greater than 0; but that the first entry is null?

 

 

On 31/08/2010, at 5:23 PM, Feras Odeh wrote:





Hello..

 

I 'm trying to create selection like tool which highlights the selected
feature but I got a null pointer exception when the code reaches the
setstyle point code

 

if(map.getMapContext().getLayers().length>0){

        map.getMapContext().getLayer(0).setStyle(style);

     //   map.getMapPane().repaint();

        }

 

The exception I got is

 

 

java.lang.NullPointerException

        at javax.swing.JComponent.repaint(JComponent.java:4748)

        at geotools.MapLayerTable.repaint(MapLayerTable.java:126)

        at org.geotools.swing.JMapPane.layerChanged(JMapPane.java:963)

        at
org.geotools.map.DefaultMapContext.fireMapLayerListListenerLayerChanged(Defa
ultMapContext.java:1035)

        at
org.geotools.map.DefaultMapContext.access$000(DefaultMapContext.java:63)

        at
org.geotools.map.DefaultMapContext$1.fireAsListEvent(DefaultMapContext.java:
101)

        at
org.geotools.map.DefaultMapContext$1.layerChanged(DefaultMapContext.java:79)

        at
org.geotools.map.DefaultMapLayer.fireMapLayerListenerLayerChanged(DefaultMap
Layer.java:537)

        at
org.geotools.map.DefaultMapLayer.setStyle(DefaultMapLayer.java:309)

        at
geotools.tools.Selection.displaySelectedFeatures(Selection.java:214)

        at geotools.tools.Selection.selectFeatures(Selection.java:189)

        at
geotools.tools.SpeculationTool.onMouseClicked(SpeculationTool.java:164)

        at
org.geotools.swing.tool.MapToolManager.mouseClicked(MapToolManager.java:130)

        at
java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)

        at
java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)

        at java.awt.Component.processMouseEvent(Component.java:6266)

        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)

        at java.awt.Component.processEvent(Component.java:6028)

        at java.awt.Container.processEvent(Container.java:2041)

        at java.awt.Component.dispatchEventImpl(Component.java:4630)

        at java.awt.Container.dispatchEventImpl(Container.java:2099)

        at java.awt.Component.dispatchEvent(Component.java:4460)

        at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)

        at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)

        at java.awt.Container.dispatchEventImpl(Container.java:2085)

        at java.awt.Window.dispatchEventImpl(Window.java:2478)

        at java.awt.Component.dispatchEvent(Component.java:4460)

        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)

        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
:269)

        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:18
4)

        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:174)

        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

 

 

So what is the problem with this code?

 

Thanks

Feras

----------------------------------------------------------------------------
--
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd________________________________________
_______
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

 

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to