views:

119

answers:

2

Still having issues with this problem. Please help if you can.

So I am trying to fix a piece of code using the Geocortex IMF framework. I get an error on line 40 which is basically pulling a null exception. It is a mix of java and html. For some reason I can't seem to find out why the error is pulling up a null. Even if I load the variable with data, it still stops at rs = activeLayer.getRecordset();

Here is the Address Form they fill out and submit

<%@ page errorPage="imfError.jsp" %>
<% 

  /*
     Program: afoAddressForm.jsp

     Purpose: Displays a page to the user to input address values for a
              USAddress type of geocoding query.
     Usage:   </>
     History: 
   */

  String layerId = request.getParameter("layerid");
  String scale = request.getParameter("scale");
  if (layerId == null) {
    throw new Exception("Missing layerid parameter.");
  }
  if (scale == null) {
    throw new Exception("Missing scale parameter.");
  }

%>
<jsp:include page="/imfCopyright.jsp"/>
<html>
<head>
<title></title>
<meta http-equiv="Content-Style-Type" content="text/css">
<link href="../../../imfStyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">
  function doNothing() {
  }
  function submitForm() {
    var strStreetName = document.frm.streetName.value;
    if (strStreetName == "") {
      alert("Please enter street name."  );
        document.frm.streetNumber.focus();
    } else {
      document.frm.action = "afoAddress.jsp?streetName="+strStreetName;
      document.frm.submit();
    }
  }
</script>
</head>
<body bgcolor="#FFFFFF" alink="#ff0000" link="#ff0000" vlink="#ff0000">
<form name="frm" action="JavaScript:doNothing()" method="post">
<input type="hidden" name="layerid" value="<%= layerId %>">
<input type="hidden" name="scale" value="<%= scale %>">
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<center>
<tr><td align="left" class="bb11">Zoom To Street<hr></td></tr>
<tr><td height="10"></td></tr>
<tr>
<td align="left" valign="top" class="bn8">
Enter the street name where you wish to centre the map. 
If matching streets are found, you will be shown a list
of matching street names for you to choose where to 
zoom the map to.

</td>
</tr>
<tr><td height="10"></td></tr>
<tr><td align="center" class="bb8">Street Name</td></tr>
<tr><td align="center" class="bb8"><input name="streetName" size="15" maxLength=40 value=""></td></tr>
<tr><td height="10"></td></tr>
<tr><td align="center" ><input name="btn" type="button" value="Submit" onclick="JavaScript:submitForm()"></td></tr>
<tr><td height="10"></td></tr>
</center>
</table>
</form>
</body>
</html>

Here is what the address form submits to

<%@ page import="com.moximedia.aims.*" %>
<% 
  /*
     Program: imfGeocodeUSAddress.jsp
              An Internet Mapping Framework (IMF) system script
              Copyright 2002 Province of British Columbia - all rights reserved
     Purpose: Displays a page of positions matching the address
              input by the user for USAddress geocoding styles.
     History: 20020610 Cates: original coding
              20030724 Cates: send user selection to separate script for labelling.
              20040525 Cates: changed frame reference top to parent
              20050103 Cates: added type to stylesheet link.
  */

  String layerId = request.getParameter("layerid");
  String scale = request.getParameter("scale");
  String StreetName = request.getParameter("streetName");

  AimsMap map = (AimsMap) (session.getAttribute("map"));
  AimsFeatureLayer activeLayer = (AimsFeatureLayer) map.getLayers().getLayer(layerId);

  AimsRecordset rs = null;
  AimsFilter streetFilter = new AimsFilter();

  if (activeLayer != null && activeLayer.getFilter()!= null) {
    streetFilter = (AimsFilter) activeLayer.getFilter();
  }

  String query_String="";
  if (StreetName == null) {
     return;
  }else{
      StreetName = StreetName.toUpperCase();
      query_String = "upper(FENAME) = '" + StreetName +"'";
      //query_String = "FENAME like '%" + StreetName +"%'";
      streetFilter.setWhereExpression(query_String);
  }

  // do the query, and whatever we need to do with the data
  rs = activeLayer.getRecordset();
  rs.clear();
  rs.clearFilter();
  rs.setMaximumResults(100);
  rs.setBufferSize(rs.getMaximumResults());
  rs.setFilter(streetFilter);
  rs.query();

  int count = 0;
  rs.moveFirst();

  while(!rs.EOF()) {
      count++;
      rs.moveNext();
  }
%>
<jsp:include page="/imfCopyright.jsp"/>
<html>
<head>
<title></title>
<meta http-equiv="Content-Style-Type" content="text/css">
<link href="imfStyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">
    function submitForm() {
        document.query.submit();
    }
</script>
</head>
<body onload="submitForm();">
<form name="query" method="post" action="afoSelectDefaultFind.jsp">
<input type="hidden" name="layerid" value="<%= layerId%>" >
<input type="hidden" name="rec" value="1" >
<input type="hidden" name="total" value="<%=count%>" >
<input type="hidden" name="query_String" value="<%=query_String%>" >
</form>
</body>
</html>

The error is when you hit submit on the form the java.lang.NullPointerException error pops up and put it on line 40 which is rs = activeLayer.getRecordset();. Any help with this would be great.

+2  A: 

Well, my guess is that activeLayer is null and then you are calling getRecordset() on a null object reference. Can you try to debug

map.getLayers().getLayer(layerId);

To make sure that it is returning something?

Chris Thompson
The layer it should be pulling is tiger_roads which is a dbf file of all the roads in a certain area. How would I figure out if map.getLayers().getLayer(layerId) is returning something? The layerId that is passed is tiger_roads.
Dennis
Well, the quick and dirty way would be to just print out the string representation of the object to the page and if it prints "null" then it's null. The better way to do it would be to use some sort of debugger and step through the page execution to examine not only the value of the activeLayer object, but also the layers collection you are referencing into. This would help you identify if there is an issue with your methods or if the id simply doesn't exist
Chris Thompson
see I tried System.out.printIn(layerId) and that throws errors as well. So I guess I should use eclipse and i should note that I am trying to do all this work on a server I don't have physical access to.
Dennis
Ack, that definitely makes it more challenging ;) What error does that throw?
Chris Thompson
Try to do a view source on your form page and make sure the "layerid" hidden field has a value, that should give you some insight in narrowing down your search.
Chris Thompson
The source for the form is up above and the value is <%= layerId %>. As far as errors that is throws I would have to do it again and see.
Dennis
Right, what I meant was view the source in a browser so you can see what actually is being rendered and sent to the user. The problem could be that <%= layerId %> isn't being evaluated correctly and the rendered HTML (what the browser uses to know what to send back) looks something like <input type="hidden" name="layerid" value="" > which would result in the getLayer() method returning null.
Chris Thompson
<body bgcolor="#FFFFFF" alink="#ff0000" link="#ff0000" vlink="#ff0000"><form name="frm" action="JavaScript:doNothing()" method="post"><input type="hidden" name="layerid" value="tiger_roads"><input type="hidden" name="scale" value="12000"><table width="95%" border="0" cellspacing="0" cellpadding="0"><center><tr><td align="left" class="bb11">Zoom To Street<hr></td></tr><tr><td height="10"></td></tr><tr><td align="left" valign="top" class="bn8">Enter the street name where you wish to centre the map.
Dennis
Hmm, that looks correct, it would be helpful to know the error it throws because it looks like that is the next area of potential problems. If you think something could be going wrong with the submission of the form, you could try a packet/http analyzer to inspect the post, but I doubt that's the issue
Chris Thompson
No the submission of the form I think is correct. I think all the problems come from the second section of code up above. All my problems start when I get to the rs = activeLayer.getRecordset(); For all I know once I pass that point I may have other errors.
Dennis
Sounds like it, I think your best bet is to either get a debugger and step through it, or get that error message and go from there
Chris Thompson
Not to be a burden on you, but I am about to leave this computer to go home and work on it there. Will you be on later to help with this problem. Because I am on a VPN here at this job I can not get the error messages (internet filters), but will be at home to give you what information you need.
Dennis
Absolutely, I'll check back fairly regularly, always happy to help!
Chris Thompson
OK, just to be sure we are on the same page. Everything with the form is ok. I am trying to add System.out.printIn(layerid) to the file to see what errors are thrown. On a side note, how would you step thru the code? By using eclipse or something of that nature.
Dennis
org.apache.jasper.JasperException: Exception in JSP:/sites/afo/jsp/afoAddress.jsp:4037: } 38:39: // do the query, and whatever we need to do with the data40: rs = activeLayer.getRecordset();41: rs.clear();42: rs.clearFilter();43: rs.setMaximumResults(100);
Dennis
Stacktrace:org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)com.moximedia.aims.servlet.filter.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:58)net.geocortex.imf.security.http.AuthorizationFilter.doFilter(AuthorizationFilter.java:147)
Dennis
root cause java.lang.NullPointerExceptionorg.apache.jsp.sites.afo.jsp.afoAddress_jsp._jspService(afoAddress_jsp.java:83)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Dennis
com.moximedia.aims.servlet.filter.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:58)net.geocortex.imf.security.http.AuthorizationFilter.doFilter(AuthorizationFilter.java:147)
Dennis
Ok, so you are getting a null pointer exception when you try to print it out, likely because it doesn't exist. It's getting wrapped in a JasperException, but the root cause is a Null Pointer exception. Is this the exception you get when you call the getRecordSet() method or try to print it out?I would use eclipse, but honestly I've never used it with JSP. I have no doubt it can be used though.
Chris Thompson
That is what I get when I call the getRecordSet(), figured I would start there then try to print it out.
Dennis
Good call, what happens if you print out "layerId"?
Chris Thompson
org.apache.jasper.JasperException: Unable to compile class for JSP: JSP FileName:/sites/afo/jsp/afoAddress.jspJava FileName:/C:/jakarta-tomcat-5.5.25/work/Catalina/localhost/imf//org/apache/jsp/sites/afo/jsp\afoAddress_jsp.javaAn error occurred at line: 21 in the jsp file: /sites/afo/jsp/afoAddress.jspThe method printIn(String) is undefined for the type PrintStream18: 19: AimsMap map = (AimsMap) (session.getAttribute("map"));20: AimsFeatureLayer activeLayer = (AimsFeatureLayer) map.getLayers().getLayer(layerId);21: System.out.printIn(layerId);22: AimsRecordset rs = null;23:
Dennis
Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:98) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435) org.apache.jasper.compiler.Compiler.compile(Compiler.java:298) org.apache.jasper.compiler.Compiler.compile(Compiler.java:277) org.apache.jasper.compiler.Compiler.compile(Compiler.java:265) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
Dennis
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) com.moximedia.aims.servlet.filter.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:58) net.geocortex.imf.security.http.AuthorizationFilter.doFilter(AuthorizationFilter.java:147)
Dennis
Ah so it would appear that System.out.println doesn't work in this instance, try out.println() instead and see what that gets us
Chris Thompson
Seems I get the same error, it always stops at the printIn function. Tried to get Eclipse to work, but there are so many errors in eclipse that it does not seem to find the right one. Plus, I can't connect to the server with it so I can not run it on there.
Dennis
can you try creating a simple page that does nothing but out.println("Hello world"). I'm at a loss, obviously something isn't right but something very strange is going on.
Chris Thompson
Yeah, I think I might have a solution. It can't compile because the file is read-only. So right now I am trying to remove the read-only attribute, at least that is what google says when I look up org.apache.jasper.JasperException. So I am trying that, because I really don't find anything wrong with the code, and the fact that it can't compile seems to be an obvious problem.
Dennis
Well, that was not the problem either. And I did find out that the AXL file may not have had the workspace in it, but there are so many that I picked the one that has the most current calls. Added the roads file in there and still seems to stop at the same spot: rs = activeLayer.getRecordSet()
Dennis
It really comes back to the the activeLayer not getting set. Basically that collection doesn't have an object in it associated with "tiger_roads." What populates that collection?
Chris Thompson
What do you mean by collection?
Dennis
The map.getLayers().getLayer() call calls into a "collection" object to get an object out of it. The getLayers() method returns the collection and then getLayer() returns the layer object, what sets the layers on the map object? Are we sure that there actually are objects inside that object that we can pull out?
Chris Thompson
How do I find out if getLayers() is actually pulling the information? I know nothing about ArcIMS, and until a few weeks ago knew nothing about Geocortex IMF. So bare with me if I am trying to figure things out, but I will pick it up pretty quickly.
Dennis
No worries at all, to be honest with you I know nothing about it either, I'm just following my own general set of debugging guidelines. You really need a debugger, you may want to google the best way to debug jsp pages. If I was doing it, and could debug it in eclipse, I would step through it and look at the contents of that variable or perhaps even use the "inspect" feature to identify if it is, in fact, returning a value that is something other than null.
Chris Thompson
Well considering that eclipse is the only free option that I have, I have it downloaded it and sitting on the server itself where the application sits. How would I connect to the application so I can try and step through the code itself? Never used eclipse before so I am clueless.
Dennis
Take a look at this tutorial, sorry I haven't been as on top of things the last few days! https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/com.sap.km.cm.docs/library/mobile/mobile-infrastructure/Mobile%20Development%20Kit%202.5/content/eclipse/debuggingineclipse.html
Chris Thompson
A: 

As Chris Thompson points out, the issue is almost certainly that the layer is null. Check that your AXL file has the right layers and layerIds. (Sorry, I know ArcIMS, but I'm not familiar with the Geocortex framework.)

Also, you should add code to check if activeLayer is null and throw a different exception than NullPointerException, since that will make the error that much more obvious to the next programmer that comes along. Interesting that the streetFilter isn't applied if activeLayer is null, so somebody thought about this at some point.

Daniel Pryden
<LAYER type="featureclass" name="Tiger Roads" visible="false" id="tiger_roads" maxscale="1:30000"> <DATASET name="tiger_roads" type="line" workspace="shp_ws-143" /> <SIMPLERENDERER> <SIMPLELINESYMBOL width="1" captype="round" color="192,192,192" /> </SIMPLERENDERER> <EXTENSION type="Geocode">
Dennis