Hi,

   i did some adjustments to my code, in particular i declared a
stylefactory object within my ConstructStyle.java and in the constructor i
added it by doing:

         this.lineStyle = styleFactory.createStyle();

to help create the style with the addition of doing declaring an instance
variable of this class called 
  private ConstructStyle constrStyle; in my ConstructMap.java and the
constructor as 

this.constrStyle = new ConstructStyle();

but in doing so i get an exepction as follows:

ava.lang.NullPointerException
        at
com.mycompany.Map_AppV2.ConstructStyle.<init>(ConstructSyle.java:87)
        at com.mycompany.Map_AppV2.ConstructMap.<init>(ConstructMap.java:50)
        at com.mycompany.Map_AppV2.MapApp.main(MapApp.java:42)

I looked on google about this particular exception to find out what it mean
and essentially it was about whether my variables were declared properly.
After doing some inspection, i noticed that these two variables do have the
keyword "this" so clearly i am missing something very small to do this. Here
is my code snippets:

ConstructStyle.java
class ConstructStyle implements StyleFactory, LineSymbolizer
{
    // Create Style using StyleFactory
    private Style lineStyle;
    private StyleFactory styleFactory;
    
    
    //private Graphics lineGraphics;
    
    // StyleBuilder helps build simple styles
    private StyleBuilder myStyleBuilder; 
    
    //  Describe how to represent a feature on screen
    private LineSymbolizer lineSymbolizer; 
    
    // 
    private FeatureTypeStyle fts;
    private Rule firstRule;
         
    ConstructStyle( )
    {
          
         this.lineStyle = styleFactory.createStyle(); // line 87
        
         this.myStyleBuilder = new StyleBuilder();// Create StyleBuilder
object  helps builds simple styles
            
        //createStyle(file,myFeatureTypeSchema);
         this.lineSymbolizer =
myStyleBuilder.createLineSymbolizer(Color.cyan); //create color to be
displayed
         lineStyle = myStyleBuilder.createStyle(lineSymbolizer); // use
mystlyebuilder object to create a style and store this in variable
             
    }
    
ConstructMap.java
class ConstructMap  implements MapContext  
{
    private String Title = "Google App";
    private String[] myFeatureTypeNames = null; // Create an array of string
to store the feature types
    private String myFeatureTypeName = null; // store type name
    private ConstructStyle constrStyle;
    
       
    ConstructMap( ) throws Exception
    {
        this.constrStyle = new ConstructStyle(); // line 50
        
        SwingFrame swingFr = new SwingFrame();
        
        
         // Declare file instance 
        File file = new File("C:/Cavendish_map_data/map_01_data.shp");
        
      

// rest of code skipped

MapApp.java
public class MapApp {

    public static void main(String[] args) 
    {
        System.out.println("Geotools version is" + " " +
GeoTools.getVersion());
        try {

            // Class which builds the map
            ConstructMap cMap = new ConstructMap();
            
            ConstructStyle constrStyle = new ConstructStyle();
        
            
        } catch (Exception ex) {
            Logger.getLogger(MapApp.class.getName()).log(Level.SEVERE, null,
ex);
        }
       
        
    }
}

I've also uploaded my in case you would like to see.

Thanks


       
   



Michael Bedward wrote:
> 
>> The problem i'm  having is in my  ConstructMap.java file where i am
>> adding
>> my featuressource and the style object to the mapcontext object as it
>> says:
>>
>> ava.lang.ClassCastException: com.mycompany.Map_AppV2.ConstructStyle
>> cannot
>> be cast to org.geotools.styling.Style
>>        at
>> com.mycompany.Map_AppV2.ConstructMap.<init>(ConstructMap.java:81)
>>        at com.mycompany.Map_AppV2.MapApp.main(MapApp.java:41)
>>
> 
> If you can post a snippet of your code it would help
> 
> Michael
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Geotools-gt2-users mailing list
> Geotools-gt2-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> 
> 
http://n2.nabble.com/file/n2229061/Map_AppV2.zip Map_AppV2.zip 
-- 
View this message in context: 
http://n2.nabble.com/Styling-problem-tp2227157p2229061.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to