在下面的代码中,我能够创建会话,但是我的代码给出了错误
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);