首页 \ 问答 \ JSP java.lang.NullPointerException(JSP java.lang.NullPointerException)

JSP java.lang.NullPointerException(JSP java.lang.NullPointerException)

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");
    }

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)

I am trying to sort a string array and receive the java.lang.NullPointerException. This is only part of the code but it is the relevant part associated with the error. I know that when I initialize the string array myRows it sets the values to null. However, I am checking for nulls and set the values of item_value, period_value, and periodAmt_value to a set value. When I print out the contents of the array it does contain the set values. Do not understand why the java.util.Arrays.sort() will not work and why it errors out. Any help is very much appreciated!!

<%

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");
    }

原文:https://stackoverflow.com/questions/19384902
更新时间:2023-12-12 07:12

最满意答案

经过广泛调查,这是logstash 1.4.2的grok表达式的最小rspec测试:

# encoding: utf-8

require "test_utils"

describe "simple test" do
  extend LogStash::RSpec

   config <<-CONFIG
    filter {
      grok {
         match        => { "message" => "am%{GREEDYDATA:foo}" }
      }
    }
  CONFIG

  sample 'amessage' do
    insist { subject["foo"] } == "essage"
    insist { subject["message"] } == "amessage"
  end
end

请注意,您必须拥有Expected "essage", but got nil # encoding ...行,否则您将获得Expected "essage", but got nil消息。

此邮件列表消息有助于: https//groups.google.com/d/msg/logstash-users/rs6jlAxv36M/1ylU-GJ-DVQJ


After extensive investigation, here's the minimal rspec test for a grok expression for logstash 1.4.2:

# encoding: utf-8

require "test_utils"

describe "simple test" do
  extend LogStash::RSpec

   config <<-CONFIG
    filter {
      grok {
         match        => { "message" => "am%{GREEDYDATA:foo}" }
      }
    }
  CONFIG

  sample 'amessage' do
    insist { subject["foo"] } == "essage"
    insist { subject["message"] } == "amessage"
  end
end

Note that you must have the # encoding ... line, otherwise you'll get the Expected "essage", but got nil message.

This mailing list message helped: https://groups.google.com/d/msg/logstash-users/rs6jlAxv36M/1ylU-GJ-DVQJ

相关问答

更多
  • 使用验证而不是验证。 Use validates instead of validate.
  • 类 MyClient 没有名为connect的方法。 试试看: MyClient.connect无法使用。 如果要检查类为其实例定义了哪些方法,请使用instance_methods : MyClient.instance_methods.include?(:connect)将为true。 methods列出了对象本身响应的方法,因此MyClient.new(*args).methods.include?(:connect)将为true。 实际上,为了检查某个类上是否存在特定的实例方法,您应该使用metho ...
  • 这里有几件事: 当您运行规范时,您正在运行RSpec,就像应用程序一样,它的“config”在spec / spec_helper.rb中。 我会假设它是空的/不相关的。 如果您正在运行更新版本的RSpec,您可以在.rspec文件中放置--require spec_helper ,并且您的文件中不需要require "spec_helper" 。 最好在文件中第一次使用RSpec.describe而不是plain describe 。 您可以使用subject块以及described_class以获得更多 ...
  • 所以,它实际上是导致问题的spork。 您可以关闭缓存,以便每次都不需要重新启动: http://ablogaboutcode.com/2011/05/09/spork-testing-tip-caching-classes 我想这就是: ruby-1.9.2-p180 :020 > u = User.new => # u.errors => {} ruby-1.9.2-p180 :022 > u.save ...
  • 我不知道为什么,但我重构了我的测试,他们现在按预期工作。 也许这会帮助别人。 RSpec.describe User do describe 'Abilities' do context 'guest' do let(:user) { create(:user, state: 'guest') } (client_made_resources + administrator_resources).each do |r| it "cannot manage ...
  • 经过广泛调查,这是logstash 1.4.2的grok表达式的最小rspec测试: # encoding: utf-8 require "test_utils" describe "simple test" do extend LogStash::RSpec config <<-CONFIG filter { grok { match => { "message" => "am%{GREEDYDATA:foo}" } } ...
  • 发生什么情况是当您使用invalid_attributes发送请求时,您的控制器仍然会通过您的代码获取成功路径。 你可以从两次失败中看出来。 使用<[]>渲染在重定向上进行,对象实例只有id和created_at如果已保存)。 这将表明您未在Survey模型中验证name存在: # app/models/survey.rb class Survey < ActiveRecord::Base belongs_to :user validates :name, presence: true end ...
  • 这解决了我的问题。 describe Advert do it "updates budget before save" do advert = build(:advert) budget = advert.budget expect(budget.amount_spent).to eq(0) advert.save budget.reload expect(budget.amount_spent) ...
  • 由于你正在使用Mocha作为你的模拟框架,你需要告诉Rspec这个(只是将Mocha放在你的Gemfile是不够的)。 在spec_helper.rb文件中,更改以下内容: config.mock_with :rspec 对此: config.mock_with :mocha 并且所有测试都将通过。 更多信息: 如果你自己运行它,你的User模型规范实际上工作得很好: rspec spec/models/user_spec.rb 您的UsersController规范实际上是一个干扰,这就是为整个项目 ...
  • 从它看起来的代码,你应该改变: expect(menu.list).to eq({'Clockwise to Titan': 6}) 至 expect(menu.list).to eq({'Clockwise to Titan' => 6}) 使规范通过。 在您的情况下的问题是,您定义了一个hash ,其中一个键不是一个String ,而是一个Symbol 。 考虑一下: {'Clockwise to Titan': 6} == {:'Clockwise to Titan' => 6} 但 {'Clo ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)