The error that I'm getting is I'm trying to create an SQL statement
with the multiple table columns and values in the statement. So a
pseudo statement would be INSERT INTO table (col1,col2,col3) VALUES
(val1,val2,val3). The names of the columns (col1,col2...) come from a
tokenized string which I tokenize into an array of strings. So I have
a statment like this:
tokens = new java.util.StringTokenizer(MM_columnsStr,"|");
MM_columns = new String[tokens.countTokens()];
for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] =
tokens.nextToken();
Where I run into an error is that I try to create a columns_string that
in the end will have the value of "col1,col2,col3". To create this
string I first need to assign "col1" to columns_string. I've tried
statements like
columns_string = MM_columns[0];
columns_string.append(MM_columns[0]);
columns_string.append(MM_columns);
columns_string = MM_columns[1];
but I keep on getting a null pointer exception. I have declared
columns_string correctly because I can put in a simple dummy string and
the code works. The MM_columns[0] work on another set of my forms it
is getting initialized correctly at least in my other forms.
Does anyone have any ideas on how I can trouble shoot this? Anything
stick out as missing in my code?
Brian
Here's some general tips:
http://riters.com/JINX/index.cgi/Suggestions_20for_20Asking_20Questions_20on_20Newsgroups#RepeatErrorsExactly
>
> The error that I'm getting is I'm trying to create an SQL statement
> with the multiple table columns and values in the statement. So a
> pseudo statement would be INSERT INTO table (col1,col2,col3) VALUES
> (val1,val2,val3). The names of the columns (col1,col2...) come from a
> tokenized string which I tokenize into an array of strings. So I have
> a statment like this:
>
> tokens = new java.util.StringTokenizer(MM_columnsStr,"|");
> MM_columns = new String[tokens.countTokens()];
> for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] =
> tokens.nextToken();
>
> Where I run into an error is that I try to create a columns_string that
> in the end will have the value of "col1,col2,col3". To create this
> string I first need to assign "col1" to columns_string. I've tried
> statements like
>
> columns_string = MM_columns[0];
> columns_string.append(MM_columns[0]);
> columns_string.append(MM_columns);
> columns_string = MM_columns[1];
>
> but I keep on getting a null pointer exception. I have declared
> columns_string correctly because I can put in a simple dummy string and
> the code works. The MM_columns[0] work on another set of my forms it
> is getting initialized correctly at least in my other forms.
>
> Does anyone have any ideas on how I can trouble shoot this? Anything
> stick out as missing in my code?
NullPointerException (NPE) means something is null when it shouldn't be.
It's important that you find out exactly what line this NPE is occuring on.
See the link I mentioned above for how to diagnose the stack trace to
determine which line the problem lies on.
If you're still stuck, post that line and some surrounding code for us
to take a look at.
- Oliver
<%
if (request.getParameter("MM_update") != null ) {
MM_editQuery = new StringBuffer("INSERT INTO
").append(MM_editTable).append(" (");
String columns = new String();
columns = MM_columns[1]; // this is where the error is at
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// more lines of code
}
%>
<%
// create one result set (no conditions for this running)
%>
<% // create the next result set (no conditions)
// this is where the trace points a null pointer exception
Driver DriverrsDataSubj =
(Driver)Class.forName(MM_EDMREPO_DRIVER).newInstance();
// more lines of code
%>
It would seem to be a simple problem of assigning a string array
element to a string in Java.
I almost forgot to put in the error message. This is the first block:
org.apache.jasper.JasperException
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
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)
And heres the trace:
java.lang.NullPointerException
at
org.apache.jsp.businessentity_0002dadd_jsp._jspService(businessentity_0002dadd_jsp.java:146)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
Brian
So I'll show again where this array gets initialized in this segment of
code further up in the code:
String MM_columnsStr =
"business_entity_id|none,none,NULL|business_entity_type_id|..."
tokens = new java.util.StringTokenizer(MM_columnsStr,"|");
MM_columns = new String[tokens.countTokens()];
for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] =
tokens.nextToken();
I added the java.util.* class to my JSP at the top in hopes that the
problem was that the tokenizer wasn't working but I get the same error.
So the top line looks like this:
<%@ page contentType="text/html; charset=windows-1252" language="java"
import="java.sql.*,java.util.*" %>
I know I'm throwing all kinds of lines of code around but I think I'm
on the right track.
Brian
Brian
..think again. I suggest you put aside the JSP's for the moment
and develop some Java programs meant to be run from the command
line, until you get the hang of the language. Command line programs
are much easier to debug than anything coming from a server.
Andrew T.