我正在製作SFTP
的程序NetBeans
。什麼是解引用可能的空指針?
我的代碼一些部分:
com.jcraft.jsch.Session sessionTarget = null;
com.jcraft.jsch.ChannelSftp channelTarget = null;
try {
sessionTarget = jsch.getSession(backupUser, backupHost, backupPort);
sessionTarget.setPassword(backupPassword);
sessionTarget.setConfig("StrictHostKeyChecking", "no");
sessionTarget.connect();
channelTarget = (ChannelSftp) sessionTarget.openChannel("sftp");
channelTarget.connect();
System.out.println("Target Channel Connected");
} catch (JSchException e) {
System.out.println("Error Occured ======== Connection not estabilished");
log.error("Error Occured ======== Connection not estabilished", e);
} finally {
channelTarget.exit(); // Warning : dereferencing possible null pointer
channelTarget.disconnect(); // Warning : dereferencing possible null pointer
sessionTarget.disconnect(); // Warning : dereferencing possible null pointer
}
我得到警告dereferencing possible null pointer
,我怎麼能解決這些警告??? 我可以在哪裏斷開我的Session
和Channel
???
我明白你在說什麼,但我該如何解決這個問題? –
@AnkitLamba:更新回答 –