ArrayList 大小不在 logcat
ArrayList size not in logcat
我试图在 Logcat 中显示以下代码的数组大小,但没有显示任何内容。
怎么了?
有人可以帮忙吗?
@Override
protected Topic[] doInBackground(final Object... params) {
try {
final List<Topic> topics = new ArrayList<Topic>();
int page = 0;
int maxPage = 10;
while (page < maxPage) {
final String url = search.toURL();
final byte[] data = Downloader.download(url);
if (data != null) {
final ForumPage fp = Parser.parseForumPage(data);
page = fp.getPage();
maxPage = fp.getMaxPage();
for (final Topic t : fp.getTopics()) {
final String v = getVersion(t);
if (v != null && Util.compareVersions(v, minVersion) > 0){
topics.add(t);
}
System.out.println("SIZE: " + topics.size());
}
search.setStart(fp.getNextPageStart());
}
}
return topics.toArray(new Topic[topics.size()]);
} catch (final Exception e) {
Log.e(Constants.LOG, e.getMessage(), e);
}
return null;
}
您的 Log 语句在 While 循环之外。一个原因可能是 while 循环中存在一些异常,因此 while 循环外的代码没有被调用。
尝试在 while 循环中添加日志语句,看看它是否有效。这样你就可以确认它是 while 循环的问题还是在你的日志语句中。
这样试试:
Log.w("Size: ", "The size "+topics.size());
还要检查代码是否达到了上面一行。我的意思是,如果在它之前抛出异常,那么它将进入 catch
块。
我试图在 Logcat 中显示以下代码的数组大小,但没有显示任何内容。 怎么了? 有人可以帮忙吗?
@Override
protected Topic[] doInBackground(final Object... params) {
try {
final List<Topic> topics = new ArrayList<Topic>();
int page = 0;
int maxPage = 10;
while (page < maxPage) {
final String url = search.toURL();
final byte[] data = Downloader.download(url);
if (data != null) {
final ForumPage fp = Parser.parseForumPage(data);
page = fp.getPage();
maxPage = fp.getMaxPage();
for (final Topic t : fp.getTopics()) {
final String v = getVersion(t);
if (v != null && Util.compareVersions(v, minVersion) > 0){
topics.add(t);
}
System.out.println("SIZE: " + topics.size());
}
search.setStart(fp.getNextPageStart());
}
}
return topics.toArray(new Topic[topics.size()]);
} catch (final Exception e) {
Log.e(Constants.LOG, e.getMessage(), e);
}
return null;
}
您的 Log 语句在 While 循环之外。一个原因可能是 while 循环中存在一些异常,因此 while 循环外的代码没有被调用。
尝试在 while 循环中添加日志语句,看看它是否有效。这样你就可以确认它是 while 循环的问题还是在你的日志语句中。
这样试试:
Log.w("Size: ", "The size "+topics.size());
还要检查代码是否达到了上面一行。我的意思是,如果在它之前抛出异常,那么它将进入 catch
块。