Jump to content

java.lang.NullPointerException

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
tomitzel

tomitzel

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Hey,
Can someone give me a work-around sollution for this exception.

String[] folders;

			folders = getPathName(remoteFile).split("/");

			

			

			

			for(i = 1; i<folders.length-1; i++){				

				ftp.makeDirectory(folders[i]);

				ftp.changeWorkingDirectory(folders[i]);

			}
The exception is given at the line:
ftp.makeDirectory(folders[i]);

#2
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
A null pointer means that a variable isn't defined or accessible.

Look to see where you defined ftp and make sure you have started an ftp connection and the makeDirectory method is available to you where its at.

#3
tomitzel

tomitzel

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
yeah I know but I couldn't figure it out which one.
It turned out it was the ftp variable :P

#4
navghost

navghost

    Newbie

  • Members
  • PipPip
  • 17 posts
Maby You should write this like that ;)
String[] folders;
folders = getPathName(remoteFile).split("/");

if(folders != null && folders.length > 0) {			
  for(i = 0; i<folders.length; i++){
    if(folders[i] != null) {				
      ftp.makeDirectory(folders[i]);
      ftp.changeWorkingDirectory(folders[i]);
    } else {
      /*Current folder (folder[i]) doesn't exist.*/
    }
  }
} else {
  /*Folders of array object is null or empty.*/
}
Have fun!
"Work should be challenging and the challenge should be fun. Great just isn't good enough!"

#5
tomitzel

tomitzel

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
before i do that i call a file exist method so the pathname is valid :P
thanks anyway.

#6
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

tomitzel said:

before i do that i call a file exist method so the pathname is valid :P
thanks anyway.

You can do it with try and catch :)
Posted Image

#7
witson

witson

    Newbie

  • Members
  • Pip
  • 4 posts
have u tried this() as rec'd by navghost:

navghost said:

Maby You should write this like that ;)

String[] folders;

folders = getPathName(remoteFile).split("/");


if(folders != null && folders.length > 0) {			

  for(i = 0; i<folders.length; i++){

    if(folders[i] != null) {				

      ftp.makeDirectory(folders[i]);

      ftp.changeWorkingDirectory(folders[i]);

    } else {

      /*Current folder (folder[i]) doesn't exist.*/

    }

  }

} else {

  /*Folders of array object is null or empty.*/

}

Have fun!