In openFileOutput Android, NullPointerException
<p>NullPointerException occurs from openFileOutput.
context.getPackageName() = android, This code is framework.
I don't know this problem, context or anything...
Can anyone help me please?</p>

<p>-use to contacts app</p>

<p>02-16 02:06:42.449: I/VCardImport(2255): vCard cache thread starts running.</p>

<p>02-16 02:06:42.449: E/VCardImport(2255): filename : import_tmp_0.vcf</p>

<p>02-16 02:06:42.449: E/VCardImport(2255): file : /data/data/com.android.contacts/files/import_tmp_0.vcf</p>

<p>-My source, framework</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): filename : import_tmp_0.vcf</p>

<p>02-16 01:11:00.525: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): file : import_tmp_0.vcf</p>

<p>My source's context is 'android', when I use functions which is getFileStreamPath, openFileOutput, I cannot create file. I think the context cause the problem. I want to know  what cause the problem and how to solve the problem.
context.getFileStreamPath(filename);
context.openFileOutput(filename, Context.MODE_PRIVATE).getChannel();</p>

<p>private Uri copyTo(final Uri sourceUri, String filename) throws IOException {</p>

<pre><code>    Log.i(LOG_TAG, String.format("Copy a Uri to app local storage (%s -&gt; %s)",
            sourceUri, filename));
    final Context context = mContext.get();
    final ContentResolver resolver = context.getContentResolver();
    ReadableByteChannel inputChannel = null;
    WritableByteChannel outputChannel = null;
    Uri destUri = null;
    try {
        inputChannel = Channels.newChannel(resolver.openInputStream(sourceUri));
        destUri = Uri.parse(context.getFileStreamPath(filename).toURI().toString());
        outputChannel = context.**openFileOutput**(filename, Context.MODE_PRIVATE).getChannel();

        final ByteBuffer buffer = ByteBuffer.allocateDirect(8192);

        while (inputChannel.read(buffer) != -1) {
            buffer.flip();
            outputChannel.write(buffer);
            buffer.compact();
        }

        buffer.flip();

        while (buffer.hasRemaining()) {
            outputChannel.write(buffer);
        }

    } finally {
        if (inputChannel != null) {
            try {
                inputChannel.close();
            } catch (IOException e) {
                Log.w(LOG_TAG, "Failed to close inputChannel.");
            }
        }
        if (outputChannel != null) {
            try {
                outputChannel.close();
            } catch(IOException e) {
                Log.w(LOG_TAG, "Failed to close outputChannel");
            }
        }
    }
    return destUri;
}
</code></pre>

<p>02-16 01:11:00.455: I/PstManagerService(549): onsetrecordcmd start</p>

<p>02-16 01:11:00.455: I/PstManagerService(549): f.exists</p>

<p>02-16 01:11:00.455: I/PstManagerService(549): after creteNewFile</p>

<p>02-16 01:11:00.465: W/PstContactCreator(549): pst contact start!</p>

<p>02-16 01:11:00.465: E/PstContactCreator(549): filename : import_tmp_0.vcf</p>

<p>02-16 01:11:00.465: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.475: E/PstContactCreator(549): file : import_tmp_0.vcf</p>

<p>02-16 01:11:00.475: I/PstContactCreator(549): Copy a Uri to app local storage 
(file:///cache/pst_contact_r.tmp -> import_tmp_0.vcf)</p>

<p>02-16 01:11:00.475: I/PstContactCreator(549): dcshin 111</p>

<p>02-16 01:11:00.475: E/PstContactCreator(549): inputChannel : 
java.nio.channels.Channels$InputStreamChannel@419ca7a8</p>

<p>02-16 01:11:00.475: I/PstContactCreator(549): dcshin 222</p>

<p>02-16 01:11:00.485: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.495: E/PstContactCreator(549): destUri : file:/import_tmp_0.vcf</p>

<p>02-16 01:11:00.495: I/PstContactCreator(549): dcshin 333</p>

<p>02-16 01:11:00.495: E/PstContactCreator(549): getPackageName : android</p>

<p>02-16 01:11:00.495: E/PstContactCreator(549): getPackageCodePath : null</p>

<p>02-16 01:11:00.505: E/PstContactCreator(549): getPackageResourcePath : null</p>

<p>02-16 01:11:00.505: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.505: E/PstContactCreator(549): java.lang.NullPointerException</p>

<p>02-16 01:11:00.505: I/PstContactCreator(549): Finished caching vCard.</p>

<p>02-16 01:11:00.515: I/PstManagerService(549): onsetrecordcmd start</p>

<p>02-16 01:11:00.515: I/PstManagerService(549): f.exists</p>

<p>02-16 01:11:00.515: I/PstManagerService(549): after creteNewFile</p>

<p>02-16 01:11:00.525: W/PstContactCreator(549): pst contact start!</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): filename : import_tmp_0.vcf</p>

<p>02-16 01:11:00.525: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): file : import_tmp_0.vcf</p>

<p>02-16 01:11:00.525: I/PstContactCreator(549): Copy a Uri to app local storage 
(file:///cache/pst_contact_r.tmp -> import_tmp_0.vcf)</p>

<p>02-16 01:11:00.525: I/PstContactCreator(549): dcshin 111</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): inputChannel : 
java.nio.channels.Channels$InputStreamChannel@419b0018</p>

<p>02-16 01:11:00.525: I/PstContactCreator(549): dcshin 222</p>

<p>02-16 01:11:00.525: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.525: E/ThermalDaemon(2916): Maximum CPU[1] frequency 918000 KHz</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): destUri : file:/import_tmp_0.vcf</p>

<p>02-16 01:11:00.525: I/PstContactCreator(549): dcshin 333</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): getPackageName : android</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): getPackageCodePath : null</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): getPackageResourcePath : null</p>

<p>02-16 01:11:00.525: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.525: E/PstContactCreator(549): java.lang.NullPointerException</p>

<p>02-16 01:11:00.525: I/PstContactCreator(549): Finished caching vCard.</p>

<p>02-16 01:11:00.535: I/PstManagerService(549): onsetrecordcmd start</p>

<p>02-16 01:11:00.535: I/PstManagerService(549): f.exists</p>

<p>02-16 01:11:00.535: I/PstManagerService(549): after creteNewFile</p>

<p>02-16 01:11:00.535: W/PstContactCreator(549): pst contact start!</p>

<p>02-16 01:11:00.535: E/PstContactCreator(549): filename : import_tmp_0.vcf</p>

<p>02-16 01:11:00.535: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.535: E/PstContactCreator(549): file : import_tmp_0.vcf</p>

<p>02-16 01:11:00.535: I/PstContactCreator(549): Copy a Uri to app local storage 
(file:///cache/pst_contact_r.tmp -> import_tmp_0.vcf)</p>

<p>02-16 01:11:00.535: I/PstContactCreator(549): dcshin 111</p>

<p>02-16 01:11:00.535: E/PstContactCreator(549): inputChannel : 
java.nio.channels.Channels$InputStreamChannel@414d6ca8</p>

<p>02-16 01:11:00.535: I/PstContactCreator(549): dcshin 222</p>

<p>02-16 01:11:00.535: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.545: E/PstContactCreator(549): destUri : file:/import_tmp_0.vcf</p>

<p>02-16 01:11:00.545: I/PstContactCreator(549): dcshin 333</p>

<p>02-16 01:11:00.545: E/PstContactCreator(549): getPackageName : android</p>

<p>02-16 01:11:00.545: E/PstContactCreator(549): getPackageCodePath : null</p>

<p>02-16 01:11:00.545: E/PstContactCreator(549): getPackageResourcePath : null</p>

<p>02-16 01:11:00.545: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.545: E/PstContactCreator(549): java.lang.NullPointerException</p>

<p>02-16 01:11:00.545: I/PstContactCreator(549): Finished caching vCard.</p>

<p>02-16 01:11:00.545: I/PstManagerService(549): onsetrecordcmd start</p>

<p>02-16 01:11:00.545: I/PstManagerService(549): f.exists</p>

<p>02-16 01:11:00.555: I/PstManagerService(549): after creteNewFile</p>

<p>02-16 01:11:00.555: W/PstContactCreator(549): pst contact start!</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): filename : import_tmp_0.vcf</p>

<p>02-16 01:11:00.555: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): file : import_tmp_0.vcf</p>

<p>02-16 01:11:00.555: I/PstContactCreator(549): Copy a Uri to app local storage 
(file:///cache/pst_contact_r.tmp -> import_tmp_0.vcf)</p>

<p>02-16 01:11:00.555: I/PstContactCreator(549): dcshin 111</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): inputChannel : 
java.nio.channels.Channels$InputStreamChannel@41a20ff8</p>

<p>02-16 01:11:00.555: I/PstContactCreator(549): dcshin 222</p>

<p>02-16 01:11:00.555: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): destUri : file:/import_tmp_0.vcf</p>

<p>02-16 01:11:00.555: I/PstContactCreator(549): dcshin 333</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): getPackageName : android</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): getPackageCodePath : null</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): getPackageResourcePath : null</p>

<p>02-16 01:11:00.555: W/ApplicationContext(549): Unable to create files directory files</p>

<p>02-16 01:11:00.555: E/PstContactCreator(549): java.lang.NullPointerException</p>

<p>02-16 01:11:00.555: I/PstContactCreator(549): Finished caching vCard.</p>

<p>02-16 01:11:00.565: I/DiagJNIInterface(1791): Going to send message</p>

<p>02-16 01:11:00.565: D/ShutdownThread(549): Notifying thread to start shutdown 
longPressBehavior=1
02-16 01:11:00.615: I/ShutdownThread(549): Sending shutdown broadcast...</p>
