Results 1 to 2 of 2
- 02-17-2011, 12:51 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
non-static variable cannot be referenced from astatic content
hi..m workin in jmapframe...the error is d one wich is the title
public class Main {
// private Polygon polygon1; //declare instance polygon1 variable
// private Polygon polygon2; //declare instance polygon2 variable
/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile
* and displays its contents on the screen in a map frame
*/
public class PolygonDrawer extends JPanel
{
private Polygon polygon1; //declare instance polygon1 variable
private Polygon polygon2; //declare instance polygon2 variable
public PolygonDrawer()
{
//Declare array variables
int []xpolygon1; // declare xpolygon1
xpolygon1 = new int[4]; // initialize xpolygon1
int []ypolygon1; // declare xpolygon2
ypolygon1 = new int[4]; // initialize xpolygon2
int npolygon1 = 4; // count of polygon points
int []xpolygon2; // initialize xpolygon1
xpolygon2 = new int[4]; // initialize xpolygon1
int []ypolygon2; // declare xpolygon2
ypolygon2 = new int[4]; // initialize xpolygon2
int npolygon2 = 4; // count of polygon points
//Array values for polygon1[]
xpolygon1[0]=19+100; xpolygon1[1]=16+100; xpolygon1[2]=13+100; xpolygon1[3]=14+100;
ypolygon1[0]=26+100; ypolygon1[1]=29+100; ypolygon1[2]=26+100; ypolygon1[3]=23+100;
//Array values for polygon2[]
xpolygon2[0]=19; xpolygon2[1]=16; xpolygon2[2]=13; xpolygon2[3]=14;
ypolygon2[0]=26; ypolygon2[1]=29; ypolygon2[2]=26; ypolygon2[3]=23;
polygon1 = new Polygon(xpolygon1, ypolygon1, npolygon1); //construct polygon1
polygon2 = new Polygon(xpolygon2, ypolygon2, npolygon2); //construct polygon2
}
public void paintComponent(Graphics g)
{
super.paintComponent(g); // paint background
g.fillPolygon(polygon1); // fills polygon1 shape
g.fillPolygon(polygon2); // fills polygon2 shape.
}
}
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);
FeatureSource featureSource = store.getFeatureSource();
// Create a map context and add our shapefile to it
MapContext map = new DefaultMapContext();
map.setTitle("Quickstart");
map.addLayer(featureSource, null);
// Now display the map
JMapFrame.showMap(map);
/* HERE IS THE ERROR /*
PolygonDrawer mo = new PolygonDrawer();
mo.PolygonDrawer();
}
// docs end main
// docs start cache
/**
* This method demonstrates using a memory-based cache to speed up
* the display (e.g. when zooming in and out).
*
* There is just one line extra compared to the main method, where
* we create an instance of CachingFeatureStore.
*
* @throws Exception
*/
public void usingFeatureCaching() throws Exception {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();
CachingFeatureSource cache = new CachingFeatureSource(featureSource);
// Create a map context and add our shapefile to it
MapContext map = new DefaultMapContext();
map.setTitle("Using cached features");
map.addLayer(cache, null);
// Now display the map
JMapFrame.showMap(map);
}
}
-
Please only use standard English avoiding non-standard abbreviations (if you want help), and provide enough information so that we have a chance of answering your question. Which line causes the error? What is the exact verbose error message?
public class Main {
....
Please edit your code post to use code tags, again, only if you still need help. My signature link below will show you how to use these.
Similar Threads
-
non-static variable cannot be referenced from static context...
By MadJack in forum New To JavaReplies: 5Last Post: 12-01-2010, 06:43 AM -
non-static variable cannot be referenced from a static context
By keo in forum New To JavaReplies: 5Last Post: 10-15-2010, 04:21 AM -
non-static variable grade cannot be referenced from a static context
By pictianpravin in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:59 AM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks