1

I am trying to show the array size in Logcat for below code but is doesn`t show anything. What is wrong? Can somebody pls help?

@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;
}
Bjorn
  • 135
  • 5
  • 12

2 Answers2

2

Your Log statement is outside the While loop. One reason could be, there is some exception in the while loop and so the code outside while loop is not getting called.

Try adding the log statement inside the while loop and see if it works. That way you can confirm if it is a problem with while loop or in your log statement.

Prem
  • 4,823
  • 4
  • 31
  • 63
  • i don't think this could be the issue. – Sufiyan Ghori Jan 01 '15 at 19:08
  • @sufiyan, Thanks for your suggestion. But this should be the issue because Logcat syntax is not incorrect. So only reason why we could not see is if it is not called. – Prem Jan 01 '15 at 19:10
1

Try like this:

Log.w("Size: ", "The size "+topics.size());

Also check if the code reaches the above line. I mean if there is an exception thrown before it then it will go into the catch block.

Mohammed Ali
  • 2,758
  • 5
  • 23
  • 41