Could be a compiler bug, but seems unlikely -- the code is not
particularly strange or complex from compiler standards.  More likely
you're seeing some sort of debug artifact (not unusual for single-
stepping to give some bogus line numbers at times), or you're simply
misinterpreting what you see.

On Jul 21, 1:49 am, zorglub76 <[email protected]> wrote:
> It walks like a bug, it chirps like a bug.... I need someone to
> confirm that it's a bug.
>
> I was trying to get phone numbers from the address book with this
> code:
>
> public JSONObject getAllPhones() throws JSONException{
>         String mPhoneNumberProjection[] = new String[] {
>                         Contacts.Phones.NAME, Contacts.Phones.NUMBER, 
> Contacts.Phones.TYPE
>         };
>         Uri phoneNumbersUri = Contacts.Phones.CONTENT_URI;
>         JSONObject result = new JSONObject();
>         JSONArray phones = new JSONArray();
>
>         Cursor myCursor = mApp.managedQuery(phoneNumbersUri,
> mPhoneNumberProjection, null, null, null);
>         mApp.startManagingCursor(myCursor);
>         if (!myCursor.isAfterLast()){
>                 myCursor.moveToFirst();
>                 do{
>                         JSONObject aRow = new JSONObject();
>                         for (int i = 0; i < myCursor.getColumnCount(); i++){
>                                 Log.d(LOG_TAG, myCursor.getColumnName(i) + " 
> -> " +
> myCursor.getString(i));
>                                 aRow.put(myCursor.getColumnName(i), 
> myCursor.getString(i));
>                         }
>                         phones.put(aRow);
>                 } while (myCursor.moveToNext());
>         }
>         result.put("phones", phones);
>         result.put("phoneTypes", getPhoneTypes());
>         return result;
>
> }
>
> But when there are no contacts, and !myCursor.isAfterLast() evaluates
> as "false", program steps into "for" loop. So it enters "if" block,
> skips several methods and lands in "for" loop...
>
> When I extract this loop into a separate function, everything works
> ok.
>
> I'm doing this in Eclipse Helios on 32-bit Vista. I tried cleaning the
> project, erasing Java cache, restarting computer, creating new AVD...
> I used Android 1.6 and Android 2.2, but the error stays on...
>
> Can someone explain what's going on?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to