• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot resolve symbol error occuring for a method...

 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to use the javamail program (with a few modifications). I am getting a cannot resolve symbol for the senDatMail method that I am using.
I'm not a proficent java programmer so I'm not sure why i am getting the error but my troubleshooting has lead me to the sendDatMail(args); line in my code that is causing the error.

I have spent many hours trying to get this code to work so any help would be greatly appreciated.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've put the sendDatMail() method into a separate class, which means that you can't call it from the main code of the JSP without referencing an instance of that class. THe easy fix would be simply to remove the "public class sendDatMail {" line, and the matchine closing brace; that should fix the compile error you're seeing.

Now, I have to point something out: as you're already no doubt aware, JSPs with huge tracts of Java code are ugly and very hard to work with. Modern practice is to put the vast majority of your code into separate Java classes, then reference those classes from the JSP, using as little embedded Java code as possible.
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response....

If I remove the public class sendDatMail{ line I get a null pointer exception. I pasted snippets from each section of the tomcat output below.


exception

org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

root cause

java.lang.NullPointerException
at org.apache.jsp.mail1_jsp.sendDatMail(mail1_jsp.java:99)
at org.apache.jsp.mail1_jsp._jspService(mail1_jsp.java:218)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW....I'm a bit new to coding in Java....So once I actually get this code working I'll work on cleaning it up...

Rob
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat translates your JSPs into Java files, then compiles them. The stack trace says the error message is on line 99 of file mail1_jsp.java. You have to find this file and see which is line 99, and let us know what line that corresponds to in your JSP source.

You'll find the translated Java files on the server in the "work" subdirectory of the Tomcat install. Drill down until you find it; it will be in a subdirectory of a directory whose name corresponds to the name of your web app.
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for the help...

The section in mail1.jsp.java is:



Line 99 is:

multipart.addBodyPart(messageBodyPart);
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, unfortunately, looking at your code, that's not possible. The only thing that could cause this exception would be if the variable "multipart" were null, but it's definitely been assigned before this line. In fact, looking at the code, none of the lines immediately before or after could throw a NullPointerException, either. A few lines before, though, is

if (format.equals("html"))

which could throw if "format" is null. Tracing around in the code, I see that "format" comes from calling HttpServletRequest.getParameter(), which will, as it turns out, return "null" if there's no parameter by that name. So that's where I'd start looking: is format null?

Here's a secret programmer's trick for you: Don't write

if (format.equals("html"))

but instead, train yourself to write

if ("html".equals(format))

The "equals()" method knows how to handle a null argument, so if you write it this way, no exception is thrown if format is null! Of course, it still won't work right, but at least it won't crash.

You need to change the program to supply default values for the sevlet parameters if they are null.
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sooo much...

That was it!....I hardcoded a value for format and it worked!!

Now I just have to trace the code to see why it isn't getting a value...

I really appreciate your help....

Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic