简体   繁体   English

为什么我得到:java.lang.NullPointerException?

[英]why I am getting : java.lang.NullPointerException?

I am completely new in Java and I found this script on the web (this is my modified version). 我是Java的新手,我在网上找到了这个脚本(这是我修改过的版本)。 I have created a Javabean (so I can use it in my application), but when I test it, I get this error. 我已经创建了一个Javabean(所以我可以在我的应用程序中使用它),但是当我测试它时,我得到了这个错误。 Besides, I am getting a warning "java uses or overrides a deprecated API" : 此外,我收到警告“java使用或覆盖已弃用的API”

Java Plug-in 1.6.0_45
Using JRE version 1.6.0_45-b06 Java HotSpot(TM) Client VM
User home directory = C:\Users\xyz
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
proxyHost=null
proxyPort=0
connectMode=HTTP, native.
Forms Applet version is : 10.1.2.3
NO INGRESA AL PRINT
java.lang.NullPointerException
 at JavaGetUrl.setProperty(JavaGetUrl.java:53)
 at oracle.forms.handler.UICommon.setFVP(Unknown Source)
 at oracle.forms.handler.UICommon.setFVP(Unknown Source)
 at oracle.forms.handler.UICommon.onUpdate(Unknown Source)
 at oracle.forms.handler.ComponentItem.onUpdate(Unknown Source)
 at oracle.forms.handler.JavaContainer.onUpdate(Unknown Source)
 at oracle.forms.handler.UICommon.onUpdate(Unknown Source)
 at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
 at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
 at oracle.forms.engine.Runform.processMessage(Unknown Source)
 at oracle.forms.engine.Runform.processSet(Unknown Source)
 at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
 at oracle.forms.engine.Runform.onMessage(Unknown Source)
 at oracle.forms.engine.Runform.sendInitialMessage(Unknown Source)
 at oracle.forms.engine.Runform.startRunform(Unknown Source)
 at oracle.forms.engine.Main.createRunform(Unknown Source)
 at oracle.forms.engine.Main.start(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

What I want to do with this code is: 我想用这段代码做的是:

  • Capture (to a variable) the text contained in the URL (I understand that this is actually what it does) 捕获(到变量)URL中包含的文本(我知道这实际上是它的作用)
  • If the link I pass, generates a HTML or PDF file, then create it or save it in the local machine (any suggestion how to achieve this or any other JAVA that get it done will be really appreciate it) 如果链接我通过,生成一个HTML或PDF文件,然后创建它或将其保存在本地机器中(任何建议如何实现这个或任何其他JAVA完成它将真的很感激它)

Here is my actual java source file: 这是我的实际java源文件:

import java.io.*;
import java.net.*;
import oracle.forms.properties.*;
import oracle.forms.ui.*;

public class JavaGetUrl  extends VTextArea {
private static final ID GEN = ID.registerProperty("cre");


      //-----------------------------------------------------//
      //  Step 1:  Start creating a few objects we'll need.
      //-----------------------------------------------------//

      URL u;
      InputStream is = null;
      DataInputStream dis;
      String s;


    public boolean setProperty(ID id, Object value) {
                boolean retorno = true;
      try {
          System.out.println("INGRESA AL TRY");  
       if (id == GEN) {

           System.out.println("INGRESA AL IF");  

         //------------------------------------------------------------//
         // Step 2:  Create the URL.                                   //
         //------------------------------------------------------------//
         // Note: Put your real URL here, or better yet, read it as a  //
         // command-line arg, or read it from a file.                  //
         //------------------------------------------------------------//

         u = new URL("http://200.210.220.1:8080/index.shtml");

        //----------------------------------------------//
         // Step 3:  Open an input stream from the url.  //
         //----------------------------------------------//

         is = u.openStream();         // throws an IOException

         //-------------------------------------------------------------//
         // Step 4:                                                     //
         //-------------------------------------------------------------//
         // Convert the InputStream to a buffered DataInputStream.      //
         // Buffering the stream makes the reading faster; the          //
         // readLine() method of the DataInputStream makes the reading  //
         // easier.                                                     //
         //-------------------------------------------------------------//

                                                    //
         dis = new DataInputStream(new BufferedInputStream(is));

         //------------------------------------------------------------//
         // Step 5:                                                    //
         //------------------------------------------------------------//
         // Now just read each record of the input stream, and print   //
         // it out.  Note that it's assumed that this problem is run   //
         // from a command-line, not from an application or applet.    //
         //------------------------------------------------------------//


                                                   //
          while ((s = dis.readLine()) != null) {
            System.out.println(s);
         }
       }
       else {
                System.out.println("NO INGRESA AL PRINT");  
                return false;
            }
      } catch (MalformedURLException mue) {

         System.out.println("Ouch - a MalformedURLException happened.");
         mue.printStackTrace();
         System.exit(1);

      } catch (IOException ioe) {
         System.out.println("Oops- an IOException happened.");
         ioe.printStackTrace();
         System.exit(1);

      } 

      finally {


         //---------------------------------//
         // Step 6:  Close the InputStream  //
         //---------------------------------//

         try {
            is.close();
         } catch (IOException ioe) {
            // just going to ignore this one
         }

      } // end of 'finally' clause
     return retorno;
    }
} // end of class definition

如果在该尝试的中间发生异常, is null,但是最终将被调用并尝试关闭它

Seems some variable is null at line# 53 If I am not wrong line#53 is following: 似乎某些变量在#53行为空如果我没有错,第53行如下:

dis = new DataInputStream(new BufferedInputStream(is));

check if is (InputStream) is initialized before using it or BufferedInputStream is created successfully. 检查是否(InputStream)在使用之前已初始化,或者已成功创建BufferedInputStream。

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

相关问题 为什么我要为String数组获取java.lang.NullPointerException? - Why am I getting java.lang.NullPointerException for a String array? 不知道为什么我得到java.lang.NullPointerException - Not sure why I am getting java.lang.NullPointerException 我正在获取java.lang.NullPointerException - I am getting java.lang.NullPointerException 为什么我收到“错误500:java.lang.NullPointerException” Java Servlet - Why am i getting a “Error 500: java.lang.NullPointerException” java servlets 当我尝试在Studio中切换活动时,为什么会收到java.lang.NullPointerException错误? - Why am I getting a java.lang.NullPointerException error when I try to switch activities in studio? 为什么我在Android Studio中不断收到java.lang.nullpointerexception? - Why am I keep getting a java.lang.nullpointerexception in Android Studio? 我为什么会收到错误消息:“线程“ main”中的异常“ java.lang.NullPointerException” - why am i getting error: “Exception in thread ”main“ java.lang.NullPointerException” 为什么我得到“线程中的异常”主“java.lang.NullPointerException”? - Why am I getting “Exception in thread ”main“ java.lang.NullPointerException”? 为什么我不断收到Java.Lang.NullPointerException - Why do I keep getting Java.Lang.NullPointerException 获取java.lang.NullPointerException - Getting java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM