我是新來的android,json,處理和stackoverflow,所以請忍受我。我採取了一些處理代碼,確保它的工作,並試圖創建一個android apk。我有一個未解決的錯誤。我有一個函數,int getFeedLength()。它必須捕獲一個異常,並返回一個null。JSON異常阻止android構建
每當我返回一個空值(用其他任何東西代替它失敗),Android構建失敗,我已經看了很多在線資源無濟於事。
是否有替代方法返回null或其他可以讓構建繼續的其他方法?我嘗試了float和double,並且都導致了其他類型的錯誤。
下面是函數,如果需要的話,我可以分享整個處理素描:
int getFeedLength() {
int result;
String response = loadStrings(BASE_URL + APIKEY)[0];
if (response != null) {
try {
JSONObject root = new JSONObject(response);
JSONArray feeds = root.getJSONArray("feeds");
result = feeds.length();
println("number of feed entries: " + result);
return result;
}
catch (JSONException e) {
throw new Exception("Unable to perform action such an such");
return null;
}
}
}
以下是錯誤:
C:\Users\SYAMAN~1\AppData\Local\Temp\android3618104784291490945.pde\src\changethispackage\beforesubmitting\tothemarket\app\app.java:248: incompatible types
[javac] found : <nulltype>
[javac] required: int
[javac] return null;
確切的線是248? – Knossos 2012-03-06 08:15:37