1

I am trying to parse Vcard file. here is my code.

public void get_vcf_data(String file) throws VCardException, IOException{
         VCardParser parser = new VCardParser();
            VDataBuilder builder = new VDataBuilder();

            //String file = path;

            //read whole file to string
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(file), "UTF-8"));

            String vcardString = "";
            String line;
            while ((line = reader.readLine()) != null) {
                vcardString += line + "\n";
            }
            reader.close();

            //parse the string
            boolean parsed = parser.parse(vcardString, "UTF-8", builder);
            if (!parsed) {
                throw new VCardException("Could not parse vCard file: " + file);
            }

            //get all parsed contacts
            List<VNode> pimContacts = builder.vNodeList;

            //do something for all the contacts
            for (VNode contact : pimContacts) {
                ArrayList<PropertyNode> props = contact.propList;

                //contact name - FN property
                String name = null;
                String number = null;
                String tel = null;
                for (PropertyNode prop : props) {
                    if ("FN".equals(prop.propName)) {
                        name = prop.propValue;
                        Contact_name.add(name);
                        Log.d("Name", name);
                        //we have the name now
                        break;
                    }
                }
                for (PropertyNode prop : props) {
                    if ("N".equals(prop.propName)) {
                        number = prop.propValue;
                        Contact_number.add(number);
                        Log.d("Name", number);
                        //we have the name now
                        break;
                    }
                }
                for (PropertyNode prop : props) {
                    if(" TEL".equals(prop.propName))
                    {
                        tel = prop.propValue;
                        Contact_tel.add(tel);
                        Log.d("Name", tel);
                    }
                }
                Log.d("Tag", ""+Contact_name.size()+"::"+Contact_number.size()+"::"+Contact_tel.size());

                //similarly for other properties (N, ORG, TEL, etc)
                //...

                System.out.println("Found contact: " + name);
            }
}

but facing problem in while loop

while ((line = reader.readLine()) != null) {
                vcardString += line + "\n";
            }

continuously looping inside a while loop and doesn't exit from loop once it is entered

Rupal Thanki
  • 335
  • 2
  • 15
  • Why do you load the entire file into a single string, instead of parsing it one line after another? – android developer Apr 19 '13 at 13:52
  • sometimes continuously looping and this error is Occurred 04-20 10:51:12.915: E/SpannableStringBuilder(5014): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length – Rupal Thanki Apr 20 '13 at 05:23
  • I don't think this error has anything to do with the question. In any case, it's a mistery why it occurs, but check out those links: http://stackoverflow.com/questions/13670374/android-span-exclusive-exclusive-spans-cannot-have-a-zero-length , http://stackoverflow.com/questions/14698264/span-exclusive-exclusive-spans-cannot-have-a-zero-length-error-whenever-an-editt . It seems like a bug on some keyboards apps, with the auto-suggestions feature. – android developer Apr 20 '13 at 09:41

0 Answers0