missing return statement? News to me!

Before I ask anything let be begin by saying thanks to all you people that help others on these boards, I've never posted a question before but I have often found the answers to my problems somewhere here. I'm currently working on one of my last java assignments ever and I am completely stumped as to whats going on. All I want out of this code is for it to read a txt file for a bunch of phone book entries, load them into some arrays, then sort them by first name, last name, then phone# then return the array so I can use it later on. I've got the entries loaded, I've got em sorted, but I can;t return it. When I try I get a missing return statement error. I dont know why its not returning the array, so I thought I'd ask the pros. I can get it to work fine if I dont return anything but what good is that eh?

Please forgive my terrible coding, I am in no way a real programmer, I just want to pass my classs and never think about it again 8) any help would be appreciated. Tis is built to work with an "Entry" file, if you guys need it to proceed lemme know and I will post it. Thanks.

the code....

publicclass CSCD210PhoneBook{

publicstaticvoid main(String[] args)throws IOException

{//Opening main

Scanner kb =new Scanner(System.in);

int entryCount=0;

Scanner fileScanner=null;

Entry[] array=null;

array=populateEntry(entryCount, fileScanner, kb);

}//end main array=

publicstatic Entry[] populateEntry(int entryCount, Scanner fileScanner,Scanner kb)throws IOException

{

int lineCount=0;

String fileName;

File fileHandle;

System.out.println("Which file would you like your entries pulled from?");

fileName= kb.nextLine();

fileHandle =new File(fileName);

fileScanner =new Scanner(fileHandle);

while(fileScanner.hasNext())

{

fileScanner.nextLine();

lineCount++;

}

entryCount= lineCount/8;

Entry[] array=new Entry[entryCount];

fileScanner.close();

fileHandle =new File(fileName);

fileScanner =new Scanner(fileHandle);

for(int i =0; i<array.length;i++)

{

array[i]=new Entry(fileScanner);

}

fileScanner.close();

int curPos, indexSmallest, start;

Entry temp;

for (start = 0; start >< array.length - 1; start++)

{

indexSmallest = start;

for (curPos = start + 1; curPos < array.length; curPos++)

{

if (array[indexSmallest].compareTo(array[curPos]) > 0)

{

indexSmallest = curPos;

}

}// end for

temp = array[start];

array[start] = array[indexSmallest];

array[indexSmallest] = temp;

return array;

}

}

Any help would be most appreciated.

[4311 byte] By [ichimoku22a] at [2007-11-26 21:11:11]
# 1

for (int ix = 0; ix < something; ix++) {

return something

}

The compiler can't know if ix < 10 will ever be true, so it can't know if the code will ever enter the body of the for loop, so it can't know that the return statement will be reached.

Also, note that your for loop's body could only ever be executed once, since you'll hit the return the first time through.

jverda at 2007-7-10 2:48:35 > top of Java-index,Java Essentials,New To Java...
# 2

The code you posted has mismatched braces: it needs another } at the end.

Linked with this is how - or rather when - you return array from the populateEntry()

method. You have a couple of nested for-loops and you return array inside (at the

end of) the outer loop.

The compiler is really fussy about making sure that an Entry[] is returned from this

method. If you outer for-loop never gets executed for some reason, then the return

statement will never be reached. The compiler won't accept this.

Either

(1) move the return statement outside both loops so it is always executed. This

appears to be the most logical thing - but I haven't read your code that closely. It's

just that having return at the end of a for-loop (with no "continue" in sight), doesn't

make a lot of sense.

or

(2) add another return after both loops have finished.

pbrockway2a at 2007-7-10 2:48:35 > top of Java-index,Java Essentials,New To Java...
# 3
That was it, thank you much !
ichimoku22a at 2007-7-10 2:48:35 > top of Java-index,Java Essentials,New To Java...