Java代理中的Java NullPointerException [英] Java NullPointerException in Java Agent

查看:123
本文介绍了Java代理中的Java NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个java代理。我有一个NullPointerException错误,我相信不应该发生。

I'm developing a java agent. I have an NullPointerException error which I do believe should not happen.

这是调试控制台消息:

java.lang.NullPointerException
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:719)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:646)
    at COM.ibm.JEmpower.applet.http.HttpURLConnection.getInputStream(HttpURLConnection.java:411)
    at COM.ibm.JEmpower.applet.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:703)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:399)
    at JavaAgent.NotesMain(JavaAgent.java:16)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)

这是java代理中的代码

This the code in the java agent

import lotus.domino.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
public class JavaAgent extends AgentBase {

    public void NotesMain() {
      String strAux = "[A Working URL]";
      try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();

          // (Your code goes here)

          HttpURLConnection httpCon = (HttpURLConnection) new URL(strAux).openConnection();

          httpCon.setRequestMethod("HEAD");
          httpCon.setConnectTimeout(20000);  
          httpCon.setReadTimeout(20000);

          httpCon.connect();

          System.out.println(HttpCon.getURL().toString());

          int responsecode = httpCon.getResponseCode();
          System.out.println("Response code is " + responsecode + " - " + httpCon.getResponseMessage());
      } catch(Exception e) {
          e.printStackTrace();
      }
    }

}

基本上是错误指向 System.out.println(响应代码为+ httpCon.getResponseCode()+ - + httpCon.getResponseMessage());

事实上,URL是一个有用的链接,因为我通过在浏览器中访问来尝试它。

The thing is that the URL is a working link since I've tried it by accessing in a browser.

什么可以是这个错误的可能原因?它在我为测试创建的本地笔记数据库上不起作用。但是,在一个没有在笔记中开发的普通java程序中,它可以工作。

What could be the possible reasons for this error? It doesn't work as well on a local notes db that I created for testing. However, in a normal java program not developed in notes, it works.

推荐答案

在你获得响应代码之前毫无意义送了什么。您应该首先发送请求,然后获取响应代码,然后在需要时获取响应

It's pointless getting the response code before you've sent anything. You're supposed to send the request first, then get the response code, then get the response if required

这篇关于Java代理中的Java NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆