我想返回一個ArrayList,但在最後我得到錯誤:無法找到符號。我在列表中添加了一些字符串和雙精度字符,並將其返回給它。返回ArrayList給出錯誤:找不到符號
錯誤:
./Sample.java:55: error: cannot find symbol
return placeMatch;
^
symbol: variable placeMatch
location: class Sample
1 error
考慮什麼提到關於嘗試捕捉我動了我的聲明語句頂端和我得到:
./Sample.java:54:錯誤:不兼容類型 return placeMatch; ^ 要求:字符串 發現:ArrayList的
實際代碼:
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;
}
}
固定但我現在返回時得到不兼容的類型。更新的問題。 – user2644819
更新我的回答 – BobTheBuilder
如果我這樣做,然後我得到: 錯誤:無法找到符號 公開名單