• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help needed with Null Pointer Exception

 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am getting a Null Pointer Exception in this code which is used to copy a directory from remote to local. I fail to understand why. Please help




The exception is for any command at the remote. (I tried pwd etc..)

Edited:

Sorry, forgot to add the exception messages. Please see here:



Right now exception is at this line:



but from what I can understand it is happening with any command related to sourcePath
 
Norm Radder
Bartender
Posts: 1526
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a Null Pointer Exception

Where is the exception happening? Copy the full contents of the error message and paste it here.
Make sure the catch block calls the printStackTrace method to show the error's location.
Is there a variable with a null value? Backtrack in the code to see why the variable does not have a valid value.
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
I am getting a Null Pointer Exception

Where is the exception happening? Copy the full contents of the error message and paste it here.
Make sure the catch block calls the printStackTrace method to show the error's location.
Is there a variable with a null value? Backtrack in the code to see why the variable does not have a valid value.


Sorry, I edited the main post now. It is giving exception for any code related to sourcePath. Path exists and have files, not sure why it is not reading the sourcePath
 
Norm Radder
Bartender
Posts: 1526
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" 4:
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:359)
at org.gradle.CopyTest.downloadDir(CopyTest.java:65)

Look at line at 359 in ChannelSftp and find the null value. Use a print statement to print out the values of all the variables used on line 359 to see which one has the null value.

Does the error message go with the posted code?
The error message refers to method cd
the posted coded has method lcd
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
Exception in thread "main" 4:
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:359)
at org.gradle.CopyTest.downloadDir(CopyTest.java:65)

Look at line at 359 in ChannelSftp and find the null value. Use a print statement to print out the values of all the variables used on line 359 to see which one has the null value.

Does the error message go with the posted code?
The error message refers to method cd
the posted coded has method lcd


I tried this too..Neither sourcePath nor sftpChannel is null but the sftpChannel.ls(sourcePath) gives exception.







 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the source for the ChannelSftp class? Can you look at line 359?
ChannelSftp is a third party class that I know nothing about.
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This the cd method in the ChannelSftp class:



This line is giving problems:



and this exception is thrown:
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caused by: java.lang.NullPointerException
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:337)

Can you see what is null on line 337?
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is line 337:



But how can I see what is causing the error?
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the value of io_in?
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure how can I check the value of io_in 3rd party classes.This is the entire class:

 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems I was getting Null Pointer because I did not do which I did now. Now, there is a different exception:




 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" com.jcraft.jsch.JSchException: failed to send channel request

What does the API doc for that error message say?
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update:

I could not progress much here but I think the problem is host is not excepting sftp connection. I checked through WinScp and saw that even it was falling back to Scp.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!