String array not recognized

M

mcraven.2

I'm having trouble debugging some code that I created in JSP. Advice
on the problem itself or how I can go about debugging it would be
appreciated. The way that I debug my code now is I change the JSP
webpage and then look at it through a browser to see if there is an
error in the code.

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 =
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
 
O

Oliver Wong

I'm having trouble debugging some code that I created in JSP. Advice
on the problem itself or how I can go about debugging it would be
appreciated. The way that I debug my code now is I change the JSP
webpage and then look at it through a browser to see if there is an
error in the code.

Here's some general tips:
http://riters.com/JINX/index.cgi/Su...estions_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 =
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
 
M

mcraven.2

I've looked at the error message. The line it appears to point at is
down a ways from where I'm finding the bug. I know the bug is where I
think it is by commenting out the specific line and getting no error.
What I have is a web page with a form on it. When a submit button is
hit the same web page loads but this time with a hidden value set.
When this hidden value is set the following simplified version of my
code is run:

<%
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


Oliver said:
I'm having trouble debugging some code that I created in JSP. Advice
on the problem itself or how I can go about debugging it would be
appreciated. The way that I debug my code now is I change the JSP
webpage and then look at it through a browser to see if there is an
error in the code.

Here's some general tips:
http://riters.com/JINX/index.cgi/Su...estions_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 =
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
 
M

mcraven.2

I think what I'm finding is that this value is null: MM_columns[1];

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 =
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



I've looked at the error message. The line it appears to point at is
down a ways from where I'm finding the bug. I know the bug is where I
think it is by commenting out the specific line and getting no error.
What I have is a web page with a form on it. When a submit button is
hit the same web page loads but this time with a hidden value set.
When this hidden value is set the following simplified version of my
code is run:

<%
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


Oliver said:
I'm having trouble debugging some code that I created in JSP. Advice
on the problem itself or how I can go about debugging it would be
appreciated. The way that I debug my code now is I change the JSP
webpage and then look at it through a browser to see if there is an
error in the code.

Here's some general tips:
http://riters.com/JINX/index.cgi/Su...estions_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 =
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
 
M

mcraven.2

I found the problem. The tokenizing and intializing of the
MM_columns[] array had a condition on it that I needed to modify. I'm
working with older code and I didn't think to look this over. The
tokenizing etc now has the same condition placed on it as is placed on
the segment that had the null pointer exception. Namely the JSP page
is only looking to see if the form has been up before. I may need to
improve but that is coding I can do.

Brian

I think what I'm finding is that this value is null: MM_columns[1];

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 =
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



I've looked at the error message. The line it appears to point at is
down a ways from where I'm finding the bug. I know the bug is where I
think it is by commenting out the specific line and getting no error.
What I have is a web page with a form on it. When a submit button is
hit the same web page loads but this time with a hidden value set.
When this hidden value is set the following simplified version of my
code is run:

<%
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


Oliver said:
I'm having trouble debugging some code that I created in JSP. Advice
on the problem itself or how I can go about debugging it would be
appreciated. The way that I debug my code now is I change the JSP
webpage and then look at it through a browser to see if there is an
error in the code.

Here's some general tips:
http://riters.com/JINX/index.cgi/Su...estions_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 =
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
 
A

Andrew T.

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. ...
I know I'm throwing all kinds of lines of code around but I think I'm
on the right track.

...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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top