Im trying to read a file from a fileserver by setting up an ftp connection, where the path is passed as argument to the method. I have this following line to read the file from the given path, but it is throwing a null pointer exception.
Maybe it'd be easier if you told us what was actually null.
divya anand
Greenhorn
Joined: Oct 28, 2008
Posts: 25
posted
0
Hi all,
I could not test some of your suggestions as i ran into an other problem. I'm using SFTP to read files from the fileserver (not ftp. My apologies) and the license for using it expired. Now I have to replace sftp with ftp. I would like to know how do I replace sftp with ftp. The code to establish sftp connection is shown below.
public class SftpHandler {
public static final String SFTP_HOST = "aaa.org";
public static final String SFTP_USERID = "john";
public static final String SFTP_PASSWORD = "smith";
public SftpHandler() {
}
public static Sftp getSftpConnection() throws SftpException {
SshParameters params = new SshParameters(SFTP_HOST,SFTP_USERID,SFTP_PASSWORD);
Sftp sftp = new Sftp(params);
sftp.connect();
return sftp;
}
I would like to know how to use ftp just like sftp above, but Im quite unsure whether ftp is also licensed.
Well, if that particular line is throwing the NPE (meaning that line is at the top of the stack trace, no other lines above it) then the variable "ftp" must be null at that point. Nothing else on that line could possibly throw an NPE. If you don't believe me, then try replacing it with:
You probably only need the first line - but this is an example of how you can debug a NullPointerException by figuring out exactly which thing is really null, as David suggests.