简体   繁体   English

java.lang.NullPointerException尝试从哈希图中获取特定值

[英]java.lang.NullPointerException trying to get specific values from hashmap

I've spent several frustrating days on this now and would appreciate some help. 我在此上花了令人沮丧的几天,希望能得到一些帮助。 I have a Java agent in Lotus Domino 8.5.3 which is activated by a cgi:POST from my Lotusscript validation agent which is checking that customer has filled in the Billing and delivery address form. 我在Lotus Domino 8.5.3中有一个Java代理,该代理由我的Lotusscript验证代理的cgi:POST激活,该代理正在检查客户是否已填写开票和交货地址表格。 This is the code that parses the incoming data into a HashMap where field names are mapped to their respective values. 这是将传入数据解析为HashMap的代码,在该HashMap中,字段名称被映射为它们各自的值。

HashMap hmParam = new HashMap(); //Our Hashmap for request_content data

//Grab transaction parameters from form that called agent (CGI: request_content)
if (contentDecoded != null) {
    String[] arrParam = contentDecoded.split("&");                  
    for(int i=0; i < arrParam.length; i++) {
        int n = arrParam[i].indexOf("=");
        String paramName = arrParam[i].substring(0, n);
        String paramValue = arrParam[i].substring(n + 1, arrParam[i].length());

        hmParam.put(paramName, paramValue); //Old HashMap
        if (paramName.equalsIgnoreCase("transaction_id")) {
          transactionID = paramValue;
          description = "Order " + transactionID + " from Fareham Wine Cellar";
          //System.out.println("OrderID = " + transactionID);
        }

        if (paramName.equalsIgnoreCase("amount")) {
            orderTotal = paramValue;
        }
        if (paramName.equalsIgnoreCase("deliveryCharge")) {
            shipping = paramValue;
        }
    }   
}

The block of code above dates back over a year to my original integration of shopping cart to Barclays EPDQ payment gateway. 上面的代码段可以追溯到一年多以前,我最初将购物车集成到Barclays EPDQ付款网关。 In that agent I recover the specific values and build a form that is then submitted to EPDQ CPI later on in the agent like this; 在那个代理中,我恢复了特定的值并构建了一个表单,然后将其提交给EPDQ CPI,稍后再在类似的代理中提交给它。

out.print("<input type=\"hidden\" name=\"shipping\" value=\"");
out.println(hmParam.get("shipping") + "\">");

I want to do exactly the same thing here, except when I try the agent crashes with a null pointer exception. 除了在尝试使用空指针异常使代理崩溃的情况下,我想在这里做完全相同的事情。 I can successfully iterate through the hashMap with the snippet below, so I know the data is present, but I can't understand why I can't use myHashMap.Get(key) to get each field value in the order I want them for the html form. 我可以使用下面的代码段成功遍历hashMap,所以我知道数据存在,但是我不明白为什么我不能使用myHashMap.Get(key)来按我想要的顺序获取每个字段值html表单。 The original agent in another application is still in use so what is going on? 另一个应用程序中的原始代理仍在使用中,这是怎么回事? The data too is essentially unchanged String fieldnames mapped to String values. 数据也基本上是未更改的映射到String值的String字段名。

Iterator it = cgiData.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry pairs = (Map.Entry)it.next();
    out.println("<br />" + pairs.getKey() + " = " + pairs.getValue());
    //System.out.println(pairs.getKey() + " = " + pairs.getValue());
}

I did two things that may have had an impact, in the process of trying to debug what was going on I needed these further imports; 在尝试调试正在发生的事情的过程中,我做了两件事可能会产生影响,我需要这些进一步的导入。

import java.util.Iterator;
import java.util.Map;

Although I'm not iterating over the hashMap, I've left them in in case which gives me the option of dumping the hashMap out to my system audit trail when application is in production. 尽管我没有遍历hashMap,但还是保留了它们以防万一,这使我可以选择在应用程序投入生产时将hashMap转储到我的系统审计跟踪中。 In variations of the snippet below after it started working I was able to get to any of the data I needed, even if the value was Null, and toString() also seemed to be optional again, as it made no difference to the output. 在下面的代码片段开始运行后,即使它的值为Null,我也可以获取所需的任何数据,并且toString()似乎又是可选的,因为它对输出没有影响。

String cgiValue = "";
cgiValue = hmParam.get("ship_to_lastname").toString();
out.println("<br />Lastname: " + cgiValue);
out.println("<br />Company name: " + hmParam.get("bill_to_company"));
out.println("<br />First name: " + hmParam.get("ship_to_firstname"));

The second thing I did, while trying to get code to work was I enabled the option "Compile Java code with debugging information" for the agent, this may have done something to the way the project was built within the Domino Developer client. 在尝试使代码正常工作时,我做的第二件事是为代理启用了选项“使用调试信息编译Java代码”,这可能对在Domino Developer客户机中构建项目的方式有所帮助。

I think I have to put this down to some sort of internal error created when Domino Designer compiled the code. 我认为我必须将其归结为Domino Designer编译代码时产生的某种内部错误。 I had a major crash last night while working on this which necessitated a cold boot of my laptop. 昨晚在进行此操作时,我发生了严重崩溃,因此必须对笔记本电脑进行冷启动。 You also may find that when using Domino Designer 8.5.x that strange things can happen if you don't completely close down all the tasks from time to time with KillNotes 您还会发现使用Domino Designer 8.5.x时,如果不完全通过KillNotes不完全关闭所有任务,可能会发生奇怪的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试从数据库中获取数据时出现java.lang.NullPointerException - java.lang.NullPointerException while trying to fetch data from database 尝试从radioButton(Android)获取值时出现java.lang.NullPointerException - java.lang.NullPointerException when trying to get value from radioButton (Android) 尝试从 Intent 获取 Long 变量时出现 java.lang.NullPointerException - java.lang.NullPointerException when trying to get a Long variable from an Intent java.lang.NullPointerException - java.lang.NullPointerException java.lang.NullPointerException - java.lang.NullPointerException 显示java.lang.NullPointerException - java.lang.NullPointerException 尝试在java静态中打印矩阵值时出现java.lang.NullPointerException - java.lang.NullPointerException while trying to print matrix values in java static 尝试在Java中读取txt文件时出现java.lang.NullPointerException - java.lang.NullPointerException when trying to read txt file in java 尝试获取用户时,出现在SecurityContextHolder上的Spring MVC java.lang.NullPointerException - Spring mvc java.lang.NullPointerException at SecurityContextHolder when trying to get the user 当应用程序关闭时尝试获取 mainApp 中文本字段的文本时出现 java.lang.NullPointerException - java.lang.NullPointerException when trying to get the text of a textfield in mainApp when app is closing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM