我從解析數據中收到問題時遇到問題。Android應用程序在for循環中崩潰
日誌說,問題是在這個循環:
q.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> parseObjects, ParseException e) {
for (int i = 0; i < parseObjects.size(); i++) {
Comment c = new Comment();
ParseObject o = parseObjects.get(i);
c.created = o.getCreatedAt();
c.name = o.getString(Comment.NAME);
c.text = o.getString(Comment.TEXT);
c.email = o.getString(Comment.EMAIL);
c.rating = o.getDouble(Comment.RATING);
c.isActive = true;
c.place = o.getString(Comment.PLACE);
p.comments.add(c);
}
Comment.increaseDownloaded();
}
});
當我收到小於40點的對象,它工作正常。但是,如果我收到更多,我得到這個錯誤:
05-04 11:25:20.755 1473-1473/com.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myapp, PID: 1473
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
at com.myapp.place.PlaceActivity$2$3.done(PlaceActivity.java:362)
at com.parse.FindCallback.internalDone(FindCallback.java:45)
at com.parse.FindCallback.internalDone(FindCallback.java:31)
at com.parse.Parse$4$1.run(Parse.java:792)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
任何人都知道什麼是問題?
非常感謝!
'parseObjects'爲空 –
出於某種原因,parseObjects列表爲空。您需要了解當您收到40個或更多對象時如何/發生這種情況。 – asgs
我要檢查它 – user3777879