Hi, All I have developing  one application in that I am sending
contacts to server and restoring them back to mobile. I have stored
contacts to server successfully but there is problem in restoring them
back to mobile. One of my method throws NullPointerException while
restoring. The method is

public void doImport(final String fileName, final boolean replace,
final App app) {
                try {
                        System.out.println ("Inside try block of doImport ()
method");

                        vcfFile = new File(fileName);
                        System.out.println ("After creating file");

                        final BufferedReader vcfBuffer = new
BufferedReader(new FileReader(vcfFile));

                        System.out.println ("Before calculating
size");
                        final long maxlen = vcfFile.length();

                        System.out.println ("%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%"+maxlen);

                // Start lengthy operation in a background thread
                        new Thread(new Runnable() {
                     public void run() {
                        long importStatus = 0;

                        synchronized (syncMonitor) {
                                mAction = Action.IMPORT;
                                syncFileName = fileName;
                                }

                        showNotification();
                        SQLiteDatabase db =
mOpenHelper.getWritableDatabase();
                        SQLiteStatement querySyncId =
db.compileStatement("SELECT " + SYNCID + " FROM " +
SYNCDATA_TABLE_NAME + " WHERE " + PERSONID + "=?");
                        System.out.println
("****"+querySyncId.getUniqueId());
                        SQLiteStatement queryPersonId =
db.compileStatement("SELECT " + PERSONID + " FROM " +
SYNCDATA_TABLE_NAME + " WHERE " + SYNCID + "=?");
                        System.out.println
("****"+queryPersonId.getUniqueId());
                        SQLiteStatement insertSyncId =
db.compileStatement("INSERT INTO  " + SYNCDATA_TABLE_NAME + " (" +
PERSONID + "," + SYNCID + ") VALUES (?,?)");
                        System.out.println
("****"+insertSyncId.getUniqueId());
                        Contact parseContact = new
Contact(querySyncId, queryPersonId, insertSyncId);//Iam getting
parseContact as a null
                                try {
                                        long ret = 0;
                                        do  {
                                                System.out.println ("Inside
do");
                                                System.out.println
("**************"+parseContact.firstName);
                                                System.out.println
("**************"+parseContact.emails);
                                                System.out.println
("________________"+parseContact.displayName);
                                                System.out.println
("******************"+parseContact.notes);
                                                System.out.println
("************************"+vcfBuffer.read());
                                                ret =
parseContact.parseVCard(vcfBuffer);
                                                if (ret >= 0) {
 
parseContact.addContact(getApplicationContext(), 0, replace);
                                                        importStatus
+= parseContact.getParseLen();

                                                        // Update the
progress bar
                                     app.updateProgress((int) (100 *
importStatus / maxlen));
                                                }
                                        } while (ret > 0);


                                        db.close();
                                        app.updateProgress(100);
                                synchronized (syncMonitor) {
                                        mAction = Action.IDLE;
                                        showNotification();
                                }
                                stopSelf();
                                } catch (IOException e) {
                                }
                     }
                 }).start();


                } catch (FileNotFoundException e) {
                        app.updateStatus("File not found: " +
e.getMessage());
                }
    }

LogCat generates following error message

06-22 09:58:06.577: INFO/System.out(652): %%%%%%%%%%%%%%%%%%%%%%%%%
%Inside readWebPage method
06-22 09:58:08.827: INFO/global(652): Default buffer size used in
BufferedReader constructor. It would be better to be explicit if an 8k-
char buffer is required.
06-22 09:58:08.827: INFO/System.out(652): Before while
06-22 09:58:08.837: INFO/System.out(652): ####################667
06-22 09:58:08.837: INFO/System.out(652): Name of file is%%%%%%%%/
sdcard/contactBackup.vcf
06-22 09:58:08.837: INFO/System.out(652): Inside try block of doImport
() method
06-22 09:58:08.837: INFO/System.out(652): After creating file
06-22 09:58:08.837: INFO/global(652): Default buffer size used in
BufferedReader constructor. It would be better to be explicit if an 8k-
char buffer is required.
06-22 09:58:08.837: INFO/System.out(652): Before calculating size
06-22 09:58:08.837: INFO/System.out(652): %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%667
06-22 09:58:08.927: INFO/System.out(652): ****3772424
06-22 09:58:08.927: INFO/System.out(652): ****3776576
06-22 09:58:08.927: INFO/System.out(652): ****3776032
06-22 09:58:08.937: INFO/System.out(652): Inside do
06-22 09:58:08.937: INFO/System.out(652): **************null
06-22 09:58:08.937: INFO/System.out(652): **************[]
06-22 09:58:08.937: INFO/System.out(652): ________________null
06-22 09:58:08.937: WARN/dalvikvm(652): threadid=13: thread exiting
with uncaught exception (group=0x4001b180)
06-22 09:58:08.937: ERROR/AndroidRuntime(652): Uncaught handler:
thread Thread-7 exiting due to uncaught exception
06-22 09:58:08.937: ERROR/AndroidRuntime(652):
java.lang.NullPointerException
06-22 09:58:08.937: ERROR/AndroidRuntime(652):     at
com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:
243)
06-22 09:58:08.937: ERROR/AndroidRuntime(652):     at vcard.io.VCardIO
$1.run(VCardIO.java:206)
06-22 09:58:08.937: ERROR/AndroidRuntime(652):     at
java.lang.Thread.run(Thread.java:1096)

Contact parseContact = new Contact(querySyncId, queryPersonId,
insertSyncId); Here is problem. Somebody tell me what is problem
Thanks in advance.

-- 
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