以下のコードでは、セッションを作成できますが、コードでエラーが発生します
I am getting null pointer exception here.
public void uploaddata() throws IOException, SftpException
{
File uploadFilePath;
Session session ;
Channel channel = null;
ChannelSftp sftp = null;
uploadFilePath = searchForFileInExternalStorage("video.3gp");
/* uploadFilePath=new File(Environment.getExternalStorageDirectory()
+"/video.3gp");*/
Log.e("image file path are", uploadFilePath.getPath()+"name"+uploadFilePath.getName()+"length is"+uploadFilePath.length());
byte[] bufr = new byte[(int) uploadFilePath.length()];
FileInputStream fis = new FileInputStream(uploadFilePath);
fis.read(bufr);
JSch ssh = new JSch();
try {
session =ssh.getSession(username, hostName);
System.out.println("JSch JSch JSch Session created.");
session.setPassword(password);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
System.out.println("JSch JSch Session connected.");
System.out.println("Opening Channel.");
channel = session.openChannel("sftp");
channel.connect();
sftp= (ChannelSftp)channel;
Log.e("chanel is",""+channel+"sftp"+sftp);
// server path where you want to upload file
sftp.cd(location);
}
catch(Exception e){
}
ByteArrayInputStream in = new ByteArrayInputStream(bufr);
sftp.put(in, uploadFilePath.getName(), null);
in.close();
if (sftp.getExitStatus()==-1) {
System.out.println("file uploaded");
Log.v("upload result", "succeeded");
} else {
Log.v("upload faild ", "faild");
}
以下の行は、エラー sftp.put(in, uploadFilePath.getName(), null); を生成しています。