org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
java.util.Arrays.mergeSort(Arrays.java:1156)
java.util.Arrays.sort(Arrays.java:1080)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
我正在尝试对字符串数组进行排序并接收 java.lang.NullPointerException。这只是代码的一部分,但它是与错误相关的部分。我知道当我初始化字符串数组 myRows 时,它会将值设置为 null。但是,我正在检查空值并将 item_value、period_value 和 periodAmt_value 的值设置为设定值。当我打印出数组的内容时,它确实包含设置值。不明白为什么 java.util.Arrays.sort() 不起作用以及为什么会出错。很感谢任何形式的帮助!!
<%
String item_name;
String item_value;
String period_name;
String period_value;
String periodAmt_name;
String periodAmt_value;
String annualAmt_name;
int error_count = 0;
int annualAmt_value = 0;
int totalExp = 0;
String[] myRows = new String[3];
for (int i=0; i < 3; i++)
{
item_name = "item" + i;
item_value = request.getParameter(item_name);
if (item_value == null)
{
item_value = "Rent";
}
period_name = "period" + i;
period_value = request.getParameter(period_name);
if (period_value == null)
{
period_value = "52"; //default value
}
periodAmt_name = "periodAmt" + i;
periodAmt_value = request.getParameter(periodAmt_name);
if (periodAmt_value == null)
{
periodAmt_value = "520";
}
myRows[i] = item_value + "|" + period_value + "|" + periodAmt_value;
out.println(myRows[i]);
java.util.Arrays.sort(myRows);
String text = myRows[i];
StringTokenizer st = new StringTokenizer(text, "|");
String[] myFields = new String[st.countTokens()];
out.println("<tr>");
for (int j = 0; j < myFields.length; j++)
{
myFields[j] = st.nextToken();
if(j==0)
{
out.println("<td><input type=text name=" + item_name + " value=" + myFields[j] + "></td>\n");
}