Java throws a NullPointerException when you try to do something with an
object whose value is null (ie, its not pointing to anything).  In the
code below, blob is set to null then you try to call the
getBinaryOutputStream() method on it.  You need to be sure blob is set
to a valid object before you can do anything with it.

-lkench

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Patrick O. Thurman
Sent: Friday, November 10, 2006 2:33 PM
To: Post all your questions about iText here
Subject: [iText-questions] what causes the NullPointerException


What causes the NullPointerException and why does it happen in the
following code?  What are some solutions?


import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.*;
import java.sql.SQLException;
import oracle.sql.BLOB;
import java.io.FileOutputStream;
import java.io.IOException;

public class HelloWorld {

        public static BLOB doIt(oracle.sql.ARRAY args) {

                System.out.println("Hello World");
    BLOB blob = null;
                Document document = new Document();
                try {
                        PdfWriter.getInstance(document,
blob.getBinaryOutputStream());
                        document.open();
                        document.add(new Paragraph("Hello World"));
                } catch (DocumentException de) {
                        System.err.println(de.getMessage());
                } catch (SQLException se) {
                        System.err.println(se.getMessage());
                }
                document.close();
    return(blob);
        }
}



Pat,








Patrick O. Thurman
Stephen F. Austin State University
Information Technology Services
Data Base Administrator
Phone:  (936) 468-1074
Fax:    (936) 468-1117




------------------------------------------------------------------------
-
Using Tomcat but need to do more? Need to support web services,
security? Get stuff done quickly with pre-integrated technology to make
your job easier Download IBM WebSphere Application Server v.1.0.1 based
on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

---------------------------------------------------------------------------------------------------------
This e-mail message may contain privileged and/or confidential information, and 
is intended to be received only by persons entitled to receive such 
information. If you have received this e-mail in error, please notify the 
sender immediately. Please delete it and all attachments from any servers, hard 
drives or any other media. Other use of this e-mail by you is strictly 
prohibited.


All e-mails and attachments sent and received are subject to monitoring, 
reading and archival by Monsanto. The recipient of this e-mail is solely 
responsible for checking for the presence of "Viruses" or other "Malware". 
Monsanto accepts no liability for any damage caused by any such code 
transmitted by or accompanying this e-mail or any attachment.
---------------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to