Question

I am loading from sdcard .vcf data and then putting it into database. I do this with this code :

    public void loadContactsFromSdcard() {
    Intent intent = new Intent(getBaseContext(), FileDialog.class);
    intent.putExtra(FileDialog.START_PATH, Environment.getExternalStorageDirectory().getPath());

    //can user select directories or not
    intent.putExtra(FileDialog.CAN_SELECT_DIR, false);

    //filter files, looking only for .vcf format
    intent.putExtra(FileDialog.FORMAT_FILTER, new String[] { "vcf" });

    startActivityForResult(intent, REQUEST_SAVE);
}

public synchronized void onActivityResult(final int requestCode,
        int resultCode, final Intent data) {

    String filePath = data.getStringExtra(FileDialog.RESULT_PATH);

    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == REQUEST_SAVE) {
            uti.showToast(getBaseContext(), filePath);

            File file = new File(filePath);
            FileInputStream fis = null;
            StringBuilder builder = new StringBuilder();

            try {
                fis = new FileInputStream(file);

                BufferedReader br = new BufferedReader(new InputStreamReader((InputStream)fis, "UTF-8"));

                String line;
                while ((line = br.readLine()) != null) {
                    builder.append(line).append("\n");
                }          

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (fis != null)
                        fis.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            System.out.println(builder.toString());
            contactService.updateContacts(builder.toString());

        } else if (requestCode == REQUEST_LOAD) {
            System.out.println("Loading...");
        }

    } else if (resultCode == Activity.RESULT_CANCELED) {
        Logger.getLogger(ContactListActivity.class.getName()).log(
                Level.WARNING, "file not selected");
    }
}

I thought this works but when now, apparently it doesn't. I changed phone software maybe this is the problem. The log output :

    07-29 11:15:23.913: E/AndroidRuntime(16473): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { cmp=pl..stxcontactsync/.util.FileDialog (has extras) }} to activity {pl..stxcontactsync/pl..stxcontactsync.ContactListActivity}: java.lang.NullPointerException
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2553)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.ActivityThread.access$2000(ActivityThread.java:121)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.os.Looper.loop(Looper.java:123)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.ActivityThread.main(ActivityThread.java:3701)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at java.lang.reflect.Method.invokeNative(Native Method)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at java.lang.reflect.Method.invoke(Method.java:507)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at dalvik.system.NativeStart.main(Native Method)
07-29 11:15:23.913: E/AndroidRuntime(16473): Caused by: java.lang.NullPointerException
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.content.ComponentName.<init>(ComponentName.java:75)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.content.Intent.<init>(Intent.java:2705)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at pl..stxcontactsync.ContactServiceActivity.updateContacts(ContactServiceActivity.java:79)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at pl..stxcontactsync.ContactListActivity.onActivityResult(ContactListActivity.java:298)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
07-29 11:15:23.913: E/AndroidRuntime(16473):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
07-29 11:15:23.913: E/AndroidRuntime(16473):    ... 11 more

Loading data is ok, I see in console that this is loaded properly. Then it starts to saving contacts to database and after first contact it crashes.

Was it helpful?

Solution

You have a null pointer exception. It's visible in the stack trace you submitted. updateContacts() tries to initialized an Intent with invalid parameters (with null). Seems like the component name is invalid. Try to check that, you can use the debugger.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top