Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array problem

 
Piyush Daiya
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Im having array problem.Below is the code and have denoted where the error occurs.split function is deifned earlier, i havent shown it.
Any pointers?
Piyush
---------------------------------------------
private String[] GetFullPath(String aPath) {
String pathArr[] = split(aPath, "/");
String arrFullPath[];
if(pathArr.length > 0){
arrFullPath = pathArr;

}
else {
arrFullPath [0] = "/"; ---> getting error here(variable not initialised)
}
return arrFullPath;

}

--------------------------------------
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Piyush,
You are getting error because your initialization of array is actually occurs in the "if" block.
<hr></blockquote>
This statement may never be executed. You have to initialize ellements of the array before you can use them.
Hope this will help.
[ July 09, 2002: Message edited by: Irene Loos ]
 
Piyush Daiya
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Irene,
Can u suggest modifications to the code.
If the 1st array length is zero then i wanna return "/", if not then whole array.
Piyush
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways, try this:

[ July 09, 2002: Message edited by: Irene Loos ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic