I am trying to return an ArrayList but at the very end i get error: cannot find symbol. I am adding to the list some Strings and Doubles and returning it to what called it.
error:
./Sample.java:55: error: cannot find symbol
return placeMatch;
^
symbol: variable placeMatch
location: class Sample
1 error
taking into consideration what was mentioned about the try catch i moved my declaration statement to the top and i get:
./Sample.java:54: error: incompatible types return placeMatch; ^ required: String found: ArrayList
actual code:
import java.util.ArrayList;
//...other imports
public class Sample
extends UnicastRemoteObject
implements SampleInterface {
public Sample() throws RemoteException {
}
public String invert(String city, String state) throws RemoteException {
try{
ArrayList<Object> placeMatch = new ArrayList<Object>();
// Read the existing address book.
PlaceList place =
PlaceList.parseFrom(new FileInputStream("places-proto.bin"));
// Iterates though all people in the AddressBook and prints info about them.
for (Place Placeplace: place.getPlaceList()) {
//System.out.println("STATE: " + Placeplace.getState());
if(Placeplace.getName().startsWith(city)){
placeMatch.add(Placeplace.getName());
placeMatch.add(Placeplace.getState());
placeMatch.add(Placeplace.getLat());
placeMatch.add(Placeplace.getLon());
break;
}
}
}catch(Exception e){
System.out.println("opening .bin failed:" + e.getMessage());
}
return placeMatch;
}
}