- 积分
- 30
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-4-1
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2016-8-22 00:21:55
|
显示全部楼层
回答老师关于报错的问题
打开老师的例子就报一个错,目前还不影响我使用,但是在这里也反馈给老师
进入正题,为了将清楚我遇到的问题。我重新制作了个简单的例子
上代码:
public FrmMain() throws FileNotFoundException, PrintException, IOException {
mapLayout1 = new org.meteoinfo.layout.MapLayout();
layersLegend1 = new org.meteoinfo.legend.LayersLegend();
jPanel_Layout = new javax.swing.JPanel();
jTabbedPane1 = new javax.swing.JTabbedPane();
jSplitPane1 = new javax.swing.JSplitPane();
javax.swing.GroupLayout jPanel_LayoutLayout = new javax.swing.GroupLayout(jPanel_Layout);
jPanel_Layout.setLayout(jPanel_LayoutLayout);
jPanel_LayoutLayout.setHorizontalGroup(
jPanel_LayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapLayout1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
);
jPanel_LayoutLayout.setVerticalGroup(
jPanel_LayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapLayout1, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Layout", jPanel_Layout);
jSplitPane1.setRightComponent(jTabbedPane1);
jSplitPane1.setLeftComponent(layersLegend1);
JFrame jframe = new JFrame();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(jframe.getContentPane());
jframe.getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE))
);
jframe.pack();
layersLegend1.setMapLayout(this.mapLayout1);
layersLegend1.setIsLayoutView(false);
mapLayout1.addText("这是一个为了展示报错专门创建的例子", mapLayout1.getWidth() / 2, 20, 16);
MeteoDataInfo aDataInfo = new MeteoDataInfo();
String dataDir = "D:\\Temp\\micaps\\";
String fileName = dataDir + "10101414.000";
aDataInfo.openMICAPSData(fileName);
//Get station data
StationData stationData = aDataInfo.getStationData("Precipitation6h");
//Interpolate
GridDataSetting aGDP = new GridDataSetting();
aGDP.dataExtent.minX = 60;
aGDP.dataExtent.maxX = 140;
aGDP.dataExtent.minY = -20;
aGDP.dataExtent.maxY = 60;
aGDP.xNum = 80;
aGDP.yNum = 80;
InterpolationSetting gridInterp = new InterpolationSetting();
gridInterp.setGridDataSetting(aGDP);
gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
gridInterp.setRadius(2);
gridInterp.setMinPointNum(1);
GridData gridData = stationData.interpolateData(gridInterp);
//Create legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,
ShapeTypes.Polygon);
((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);
//Create layer
VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
aLayer.setMaskout(true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
layersLegend1.repaint();
//Add or change the legend in layout
LayoutLegend aLegend;
aLegend = mapLayout1.addLegend(650, 100);
aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
aLegend.setLegendLayer(aLayer);
String drawpath = "D:\\Temp\\draw\\111.png";
mapLayout1.exportToPicture(drawpath);
}
这是一个为了展示报错专门创建的例子,完全在老师所给的MeteoInfoDemo例子基础上除去对我没用的代码而来。唯一更改部分就是我创建了一个新的JFrame。因为我要移植到WEB项目中,不能继承JFrame。这个例子在应用程序中能正常运行,是不报错的。
运行界面展示:
生成图片展示:
这个图片很难看,但重点是1、不报错。2、有标题。3、有色标!!!!
进行下一步,我将这个方法移植到WEB项目中。代码基本一样,只是方法名不同和返回一个字符串。
上代码:
@RequestMapping(path="/drawdemo",method=RequestMethod.GET)
public String Getdrawdemo(String path) throws Exception {
mapLayout1 = new org.meteoinfo.layout.MapLayout();
layersLegend1 = new org.meteoinfo.legend.LayersLegend();
jPanel_Layout = new javax.swing.JPanel();
jTabbedPane1 = new javax.swing.JTabbedPane();
jSplitPane1 = new javax.swing.JSplitPane();
javax.swing.GroupLayout jPanel_LayoutLayout = new javax.swing.GroupLayout(jPanel_Layout);
jPanel_Layout.setLayout(jPanel_LayoutLayout);
jPanel_LayoutLayout.setHorizontalGroup(
jPanel_LayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapLayout1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
);
jPanel_LayoutLayout.setVerticalGroup(
jPanel_LayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapLayout1, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Layout", jPanel_Layout);
jSplitPane1.setRightComponent(jTabbedPane1);
jSplitPane1.setLeftComponent(layersLegend1);
//报第一个错的地方
JFrame jframe = new JFrame();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(jframe.getContentPane());
jframe.getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE))
);
jframe.pack();
layersLegend1.setMapLayout(this.mapLayout1);
layersLegend1.setIsLayoutView(false);
//报第二个错的地方
mapLayout1.addText("这是一个为了展示报错专门创建的例子", mapLayout1.getWidth() / 2, 20, 16);
MeteoDataInfo aDataInfo = new MeteoDataInfo();
String dataDir = "D:\\Temp\\micaps\\";
String fileName = dataDir + "10101414.000";
aDataInfo.openMICAPSData(fileName);
//Get station data
StationData stationData = aDataInfo.getStationData("Precipitation6h");
//Interpolate
GridDataSetting aGDP = new GridDataSetting();
aGDP.dataExtent.minX = 60;
aGDP.dataExtent.maxX = 140;
aGDP.dataExtent.minY = -20;
aGDP.dataExtent.maxY = 60;
aGDP.xNum = 80;
aGDP.yNum = 80;
InterpolationSetting gridInterp = new InterpolationSetting();
gridInterp.setGridDataSetting(aGDP);
gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
gridInterp.setRadius(2);
gridInterp.setMinPointNum(1);
GridData gridData = stationData.interpolateData(gridInterp);
//Create legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,
ShapeTypes.Polygon);
((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);
//Create layer
VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
aLayer.setMaskout(true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
layersLegend1.repaint();
//Add or change the legend in layout
LayoutLegend aLegend;
//报第三个错的地方
aLegend = mapLayout1.addLegend(650, 100);
aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
aLegend.setLegendLayer(aLayer);
String drawpath = "D:\\Temp\\draw\\111.png";
mapLayout1.exportToPicture(drawpath);
return drawpath;
}
现在运行会在报一个错的地方报错!
上异常代码:
java.awt.HeadlessException: null
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207) ~[na:1.7.0_80]
at java.awt.Window.<init>(Window.java:535) ~[na:1.7.0_80]
at java.awt.Frame.<init>(Frame.java:420) ~[na:1.7.0_80]
at java.awt.Frame.<init>(Frame.java:385) ~[na:1.7.0_80]
at javax.swing.JFrame.<init>(JFrame.java:180) ~[na:1.7.0_80]
at cn.monkeylee.sample.provider.mvc.UserInfoControler.Getdrawdemo(UserInfoControler.java:1063) ~[bin/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
我上网查了下这个异常,我自己的理解是这个属于无头绘图。而JFrame属于重量级组件,需要输入设备或者显示器给他一个参数。而我这个WEB项目没有给他参数,所以报了null。我也试着网上的办法解决,最后解决不了!!
最后我的粗暴解决办法就是把异常的部分都删掉!!!
更改后的代码:
@RequestMapping(path="/drawdemo",method=RequestMethod.GET)
public String Getdrawdemo(String path) throws Exception {
mapLayout1 = new org.meteoinfo.layout.MapLayout();
layersLegend1 = new org.meteoinfo.legend.LayersLegend();
//删除了很多容器代码,.......
layersLegend1.setMapLayout(this.mapLayout1);
layersLegend1.setIsLayoutView(false);
//报第二个错的地方
mapLayout1.addText("这是一个为了展示报错专门创建的例子", mapLayout1.getWidth() / 2, 20, 16);
MeteoDataInfo aDataInfo = new MeteoDataInfo();
String dataDir = "D:\\Temp\\micaps\\";
String fileName = dataDir + "10101414.000";
aDataInfo.openMICAPSData(fileName);
//Get station data
StationData stationData = aDataInfo.getStationData("Precipitation6h");
//Interpolate
GridDataSetting aGDP = new GridDataSetting();
aGDP.dataExtent.minX = 60;
aGDP.dataExtent.maxX = 140;
aGDP.dataExtent.minY = -20;
aGDP.dataExtent.maxY = 60;
aGDP.xNum = 80;
aGDP.yNum = 80;
InterpolationSetting gridInterp = new InterpolationSetting();
gridInterp.setGridDataSetting(aGDP);
gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
gridInterp.setRadius(2);
gridInterp.setMinPointNum(1);
GridData gridData = stationData.interpolateData(gridInterp);
//Create legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,
ShapeTypes.Polygon);
((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);
//Create layer
VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
aLayer.setMaskout(true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
layersLegend1.repaint();
//Add or change the legend in layout
LayoutLegend aLegend;
//报第三个错的地方
aLegend = mapLayout1.addLegend(650, 100);
aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
aLegend.setLegendLayer(aLayer);
String drawpath = "D:\\Temp\\draw\\111.png";
mapLayout1.exportToPicture(drawpath);
return drawpath;
}
这个方法中把很多容器的代码删掉了,但是会在第二个报错点报错
异常展示:
java.lang.NullPointerException: null
at org.meteoinfo.layout.LayoutGraphic.updateControlSize(SourceFile:256) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.LayoutGraphic.setGraphic(SourceFile:175) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.LayoutGraphic.<init>(SourceFile:77) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.MapLayout.addText(SourceFile:2722) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.MapLayout.addText(SourceFile:2702) ~[MeteoInfoLib.jar:na]
at cn.monkeylee.sample.provider.mvc.UserInfoControler.Getdrawdemo(UserInfoControler.java:1052) ~[bin/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
报错的语句:
继续删除报错的的代码,删除后的代码如下:
@RequestMapping(path="/drawdemo",method=RequestMethod.GET)
public String Getdrawdemo(String path) throws Exception {
mapLayout1 = new org.meteoinfo.layout.MapLayout();
layersLegend1 = new org.meteoinfo.legend.LayersLegend();
//删除了很多容器代码,.......
layersLegend1.setMapLayout(this.mapLayout1);
layersLegend1.setIsLayoutView(false);
//报第二个错的地方
//删除了添加标题的语句!!
MeteoDataInfo aDataInfo = new MeteoDataInfo();
String dataDir = "D:\\Temp\\micaps\\";
String fileName = dataDir + "10101414.000";
aDataInfo.openMICAPSData(fileName);
//Get station data
StationData stationData = aDataInfo.getStationData("Precipitation6h");
//Interpolate
GridDataSetting aGDP = new GridDataSetting();
aGDP.dataExtent.minX = 60;
aGDP.dataExtent.maxX = 140;
aGDP.dataExtent.minY = -20;
aGDP.dataExtent.maxY = 60;
aGDP.xNum = 80;
aGDP.yNum = 80;
InterpolationSetting gridInterp = new InterpolationSetting();
gridInterp.setGridDataSetting(aGDP);
gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
gridInterp.setRadius(2);
gridInterp.setMinPointNum(1);
GridData gridData = stationData.interpolateData(gridInterp);
//Create legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,
ShapeTypes.Polygon);
((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);
//Create layer
VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
aLayer.setMaskout(true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
layersLegend1.repaint();
//Add or change the legend in layout
LayoutLegend aLegend;
//报第三个错的地方
aLegend = mapLayout1.addLegend(650, 100);
aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
aLegend.setLegendLayer(aLayer);
String drawpath = "D:\\Temp\\draw\\111.png";
mapLayout1.exportToPicture(drawpath);
return drawpath;
}
继续报错,异常如下:
java.lang.NullPointerException: null
at org.meteoinfo.layout.LayoutLegend.b(SourceFile:915) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.LayoutLegend.updateLegendSize(SourceFile:951) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.LayoutLegend.setLegendLayer(SourceFile:184) ~[MeteoInfoLib.jar:na]
at org.meteoinfo.layout.MapLayout.addLegend(SourceFile:2743) ~[MeteoInfoLib.jar:na]
at cn.monkeylee.sample.provider.mvc.UserInfoControler.Getdrawdemo(UserInfoControler.java:1089) ~[bin/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
报错的语句:
继续删除报错的语句,最终代码:
@RequestMapping(path="/drawdemo",method=RequestMethod.GET)
public String Getdrawdemo(String path) throws Exception {
mapLayout1 = new org.meteoinfo.layout.MapLayout();
layersLegend1 = new org.meteoinfo.legend.LayersLegend();
//删除了很多容器代码,.......
layersLegend1.setMapLayout(this.mapLayout1);
layersLegend1.setIsLayoutView(false);
//报第二个错的地方
//删除了添加标题的语句!!
MeteoDataInfo aDataInfo = new MeteoDataInfo();
String dataDir = "D:\\Temp\\micaps\\";
String fileName = dataDir + "10101414.000";
aDataInfo.openMICAPSData(fileName);
//Get station data
StationData stationData = aDataInfo.getStationData("Precipitation6h");
//Interpolate
GridDataSetting aGDP = new GridDataSetting();
aGDP.dataExtent.minX = 60;
aGDP.dataExtent.maxX = 140;
aGDP.dataExtent.minY = -20;
aGDP.dataExtent.maxY = 60;
aGDP.xNum = 80;
aGDP.yNum = 80;
InterpolationSetting gridInterp = new InterpolationSetting();
gridInterp.setGridDataSetting(aGDP);
gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
gridInterp.setRadius(2);
gridInterp.setMinPointNum(1);
GridData gridData = stationData.interpolateData(gridInterp);
//Create legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,
ShapeTypes.Polygon);
((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);
//Create layer
VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
aLayer.setMaskout(true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
layersLegend1.repaint();
//Add or change the legend in layout
LayoutLegend aLegend;
//报第三个错的地方
//删除报错的添加色标的代码
String drawpath = "D:\\Temp\\draw\\111.png";
mapLayout1.exportToPicture(drawpath);
return drawpath;
}
这个帖子第一次发的列子就是在这个代码基础行改的,就是增加了图层和修改了参数。本质上和这个代码是一样的!!
上运行效果:
运行没有报任何异常,只是没有标题,没有色标!!!!!!
恳请老师帮助解决!!
|
|