Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

socket.getOutputStream error

0 views
Skip to first unread message

Denis Papathanasiou

unread,
Jun 20, 1999, 3:00:00 AM6/20/99
to
Subject: socket.getOutputStream error
Newsgroups: comp.lang.java.help
Summary:
Keywords:

I've written a simple class to interact with a POP3 mail server, but I
am getting an error when I try to open an output stream in order to send
commands.

Here's the code I use:

public void sendPOP3ServerCommand(String cmd)
{
PrintWriter socketOut = null;

System.out.println("cmd="+cmd);
if( theSocket == null ) { System.out.println("send cmd: Socket is
null!"); }
else { System.out.println("send cmd: Socket is NOT null!"); }

try
{
socketOut = new
PrintWriter(theSocket.getOutputStream(), true);
socketOut.print(cmd);
socketOut.print("\r\n");
socketOut.close();
}
catch (IOException e)
{
exHandler.showExceptionFatal("ERROR: Cannot
access the POP3 mail server\n\n"+e);
}
}


The System.out.println() command are just for debugging.

The application chokes on the line:

socketOut = new PrintWriter(theSocket.getOutputStream(), true);

Here's the stack trace:

Exception in thread "main" java.lang.NullPointerException
at java.io.FileOutputStream.<init>(FileOutputStream.java:153)
at java.net.SocketOutputStream.<init>(SocketOutputStream.java:45)
at java.net.PlainSocketImpl.getOutputStream(PlainSocketImpl.java:420)
at java.net.Socket$2.run(Socket.java:350)
at java.security.AccessController.doPrivileged(NativeMethod)
at java.newSocket.getOutputStream(Socket.java:348)
at POP3Handler.sendPOP3ServerCommand(POP3Handler.java:230)
at POP3Handler.login(POP3Handler.java:53)
at POP3Test.main(CompiledCode)


Can anyone help?


Regards,

Denis Papathanasiou
papa...@systems.seas.upenn.edu
dpapath...@switchboardmail.com

0 new messages