*
The moose likes Java in General and the fly likes array problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "array problem" Watch "array problem" New topic
Author

array problem

Piyush Daiya
Ranch Hand

Joined: Jun 13, 2002
Posts: 67
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;

}

--------------------------------------


"A scientist is not person who gives right answers but a person who asks right questions"
Irene Loos
Ranch Hand

Joined: Apr 15, 2002
Posts: 78
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 ]

Irene Loos
Piyush Daiya
Ranch Hand

Joined: Jun 13, 2002
Posts: 67
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

Joined: Apr 15, 2002
Posts: 78
There are many ways, try this:

[ July 09, 2002: Message edited by: Irene Loos ]
 
jQuery in Action, 2nd edition
 
subject: array problem
 
Similar Threads
Unsorted array list
Doubt in JSP Code
NULL Values
Doubt in JSTL
input number to array --not displaying right item [code included]