I get the following error when trying to run code. Please help.
java.lang.NullPointerException
at conntecttoDB8.SSHCommandExecutor.main(SSHCommandEx ecutor.java:26)
package conntecttoDB8; import java.io.InputStream; import com.jcraft.jsch.Channel; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; public class SSHCommandExecutor { /** * @param args */ public static void main(String[] args) { //String host="xxxxxxxxxxxxxx"; String host="xxxxxxxxxxxxxxx"; String user="xxxxxxxxxxxxx"; String password="xxxxxxxxxxxx"; String command1="ls -ltr"; try{ java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); Session session=jsch.getSession(user, host, 22); session.setPassword(password); session.setConfig(config); session.connect(); System.out.println("Connected"); Channel channel=session.openChannel("exec"); channel.setCommand(command1); channel.setInputStream(null); channel.setInputStream(System.err); InputStream in=channel.getInputStream(); channel.connect(); byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0)break; System.out.print(new String(tmp, 0, i)); } if(channel.isClosed()){ System.out.println("exit-status: "+channel.getExitStatus()); break; } try{Thread.sleep(1000);}catch(Exception ee){} } channel.disconnect(); session.disconnect(); System.out.println("DONE"); }catch(Exception e){ e.printStackTrace(); } finally { } } } package com.jcraft.jsch; import java.util.Properties; public class Session { public void connect() { } public Channel openChannel(String string) { return null; } public void setConfig(Properties config) { } public void setPassword(String password) { } public void disconnect() { } } package com.jcraft.jsch; import java.io.PrintStream; public class ChannelExec { public void setCommand(String command1) { } public void setErrStream(PrintStream err) { } } package com.jcraft.jsch; import java.io.InputStream; public class Channel { public void setInputStream(Object object) { } public InputStream getInputStream() { return null; } public void connect() { } public boolean isClosed() { return false; } public String getExitStatus() { return null; } public void disconnect() { } public void setCommand(String command1) { } }