Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:11:20+00:00 2026-06-01T10:11:20+00:00

you must have seen this piece of code somewhere else too,but obviously there’s no

  • 0

you must have seen this piece of code somewhere else too,but obviously there’s no answer for this exception.

EDIT: IF You’ve come here finding a solution to restoring contacts via vcardio.This is IT!!

I got this while utilising the vCardIO api for android used to restore contacts from vcard to the contacts db.I have been using the following doImport() method which is supposed to work just fine,but it isnt!

 public void doImport(final String fileName, final boolean replace) {
    try {

        File vcfFile = new File(fileName);

        final BufferedReader vcfBuffer = new BufferedReader(new FileReader(fileName),1048576);

        final long maxlen = vcfFile.length();

        // Start lengthy operation in a background thread

        long importStatus = 0;

                SQLiteDatabase db = mOpenHelper.getWritableDatabase();
                SQLiteStatement querySyncId = db.compileStatement("SELECT " + SYNCID + " FROM " + SYNCDATA_TABLE_NAME + " WHERE " + PERSONID + "=?");
                SQLiteStatement queryPersonId = db.compileStatement("SELECT " + PERSONID + " FROM " + SYNCDATA_TABLE_NAME + " WHERE " + SYNCID + "=?");
                SQLiteStatement insertSyncId = db.compileStatement("INSERT INTO  " + SYNCDATA_TABLE_NAME + " (" + PERSONID + "," + SYNCID + ") VALUES (?,?)");
                db.close();
                Contact parseContact = new Contact(querySyncId, queryPersonId, insertSyncId);
                String popa="";
                popa=parseContact.getContent();
                try {
                    long ret = 0;
                    do  {

                        ret = parseContact.parseVCard(vcfBuffer);
                        //this is the snippet line which has the potential to beat the blues out of any programmer,always throwing an exception!
                        parseContact.addContact(CO, 0, true);
} while (ret > 0);

                    db.close();


                } catch (Exception e) {

                     Toast.makeText(CO,"NO "+e.getMessage()+"-"+e.getLocalizedMessage()+"-"+e.toString(), Toast.LENGTH_SHORT).show();

                }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:11:22+00:00Added an answer on June 1, 2026 at 10:11 am

    Thanks,but no thanks.I managed it myself,Alhumdulillah.Make the following changes to

    doImport();

    Method of VCardIO:

         public void doImport(final String fileName, final boolean replace) {
        try {
    
            File vcfFile = new File(fileName);
    
            final BufferedReader vcfBuffer = new BufferedReader(new FileReader(fileName),1048576);
    
            final long maxlen = vcfFile.length();
    
    
            long importStatus = 0;
    
                    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
                    SQLiteStatement querySyncId = db.compileStatement("SELECT " + SYNCID + " FROM " + SYNCDATA_TABLE_NAME + " WHERE " + PERSONID + "=?");
                    SQLiteStatement queryPersonId = db.compileStatement("SELECT " + PERSONID + " FROM " + SYNCDATA_TABLE_NAME + " WHERE " + SYNCID + "=?");
                    SQLiteStatement insertSyncId = db.compileStatement("INSERT INTO  " + SYNCDATA_TABLE_NAME + " (" + PERSONID + "," + SYNCID + ") VALUES (?,?)");
                    db.close();
                    Contact parseContact = new Contact(querySyncId, queryPersonId, insertSyncId);
                    String popa="";
                    popa=parseContact.getContent();
                    try {
                        long ret = 0;
                        do  {
    
                            ret = parseContact.parseVCard(vcfBuffer);
    
                            /* GOOGLE CODE IS JUST THIS ON LINE WHICH AIN'T WORKING!!
                            parseContact.addContact(CO, 0, true); */
    
                            if (ret >= 0) {
                                String DisplayName = parseContact.displayName;
    
    
                                List<RowData> MobileNumbers=parseContact.phones;
                                List <RowData> Addresses = parseContact.addrs;
                                List <RowData> IMs = parseContact.ims;
                                List <OrgData> Orgs = parseContact.orgs;
                                String Notes = parseContact.notes;
                                byte[] dp = parseContact.photo;
                                String BirthDay = parseContact.birthday;
    
    
                                ContentResolver cr = CO.getContentResolver();
    
                                List<RowData> mails=parseContact.emails;
    
                                try 
                                    {
    
    
                                    // ADDING NAME
                                ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
                                int rawContactInsertIndex = ops.size();
    
                                ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                                        .withValue(RawContacts.ACCOUNT_TYPE, null)
                                        .withValue(RawContacts.ACCOUNT_NAME, null).build());
                                ops.add(ContentProviderOperation
                                        .newInsert(ContactsContract.Data.CONTENT_URI)
                                        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,rawContactInsertIndex)
                                        .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
                                        .withValue(StructuredName.DISPLAY_NAME, DisplayName) // Name of the person
                                        .build());
    
                                //ADDING PHONES
                               for(RowData l : MobileNumbers)
                                {
    
                                   {
                                ops.add(ContentProviderOperation
                                        .newInsert(ContactsContract.Data.CONTENT_URI)
                                        .withValueBackReference(
                                                ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
                                        .withValue(ContactsContract.Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
    
                                        .withValue(Phone.NUMBER,l.data) 
                                        .withValue(Phone.TYPE,l.type).build());
                                   }
    
                                }
                               //ADDING MAILS
                               for(RowData a :mails)
                               {
    
                                   {
                                       ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
                                            .withValue(ContactsContract.Data.MIMETYPE, Email.CONTENT_ITEM_TYPE)
    
                                            .withValue(Email.DATA,a.data)
                                            .withValue(Email.TYPE, a.type).build()); 
                                   }
    
    
                               }
    
                               //ADDING ADDRESSES
    
                               for(RowData add :Addresses)
                               {
                                  ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
    
                                            .withValue(ContactsContract.Data.MIMETYPE,StructuredPostal.CONTENT_ITEM_TYPE)
    
                                            .withValue(StructuredPostal.DATA,add.data) 
                                            .withValue(StructuredPostal.TYPE, add.type).build()); 
                               }
    
                               //ADDING ORGANISATIONS
    
    
                               for(OrgData org :Orgs)
                               {
                                  ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
    
                                            .withValue(ContactsContract.Data.MIMETYPE,Organization.CONTENT_ITEM_TYPE)
    
                                            .withValue(Organization.DATA,org.company) 
                                            .withValue(Organization.TYPE, org.type)
                                            .withValue(Organization.TITLE, org.title)
                                            .withValue(Organization.LABEL, org.customLabel)
    
                                            .build()); 
                               }
    
                               //ADDING IMs
    
                               for(RowData IM :IMs)
                               {
                                  ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
                                            .withValue(ContactsContract.Data.MIMETYPE,Im.CONTENT_ITEM_TYPE)
    
                                            .withValue(Im.DATA,IM.data) 
                                            .withValue(Im.TYPE, IM.type).build()); 
                               }
    
                               //ADDING NOTES
    
                               if(Notes!=null && !Notes.equals(""))
                               {
                                  ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
    
                                            .withValue(ContactsContract.Data.MIMETYPE,Note.CONTENT_ITEM_TYPE)
    
                                            .withValue(Note.NOTE,Notes).build()); 
    
                               }
    
                               // ADDING PHOTO
    
                               if(dp!=null)
                               {
                                  ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
    
                                            .withValue(ContactsContract.Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE)
    
                                            .withValue(Photo.PHOTO,dp).build());
    
                               }
    
                               //ADDING BIRTHDAY
                               if(BirthDay!=null && !BirthDay.equals(""))
                               {
                                  ops.add(ContentProviderOperation
                                            .newInsert(ContactsContract.Data.CONTENT_URI)
                                            .withValueBackReference(
                                                    ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex)
    
    
                                            .withValue(ContactsContract.Data.MIMETYPE,CommonDataKinds.Event.CONTENT_ITEM_TYPE)
    
                                            .withValue(CommonDataKinds.Event.START_DATE,BirthDay)
                                            .withValue(CommonDataKinds.Event.TYPE,CommonDataKinds.Event.TYPE_BIRTHDAY).build()); // Number of the person
    
                               }
    
    
                                                        cr.applyBatch(ContactsContract.AUTHORITY, ops);
    
                                                    } 
                                                    catch (Exception e) 
                                                    {               
                                                        e.printStackTrace();
                                                        Toast.makeText(CO, "Exception: "+e.toString()+"Eebolra:" + e.getMessage(), Toast.LENGTH_SHORT).show();
                                                    }
    
    
                                importStatus += parseContact.getParseLen();
    
    
                            }
                            db.close();
                            } while (ret > 0);
    
                        db.close();
    
                    } catch (Exception e) {
    
                         Toast.makeText(CO,"NO "+e.getMessage()+"-"+e.getLocalizedMessage()+"-"+e.toString(), Toast.LENGTH_SHORT).show();
    
                    }
    
    
    
        } catch (FileNotFoundException e) {
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK i have seen other posts about this but none really specifically answer my
This must have an obvious solution, but I'm stumped. We are developing an application
This must have been answered previously, but my Google powers are off today and
Apologies in advance but I have never seen this error before and don't know
I have reviewed numerous reports of this error but the solutions I have seen
I believe I've seen this in javascript options somewhere, but I coudln't find it
I have seen this question: Are there any decent UI components for touch screen
I have seen similar questions to this, but they involve different types so I
OK, this must have been asked before but I looked like mad and found
I have seen this asked and followed everything but it simply doesnt work for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.