what is line 39 in your source file?
are the filename and contents non-null?
btw, i'd recommend closing the output stream writer in a finally
block. finalizers aren't guaranteed to get called.
>I have two methods, one reads files and one writes the given string to
>a file.
>For some reason, the first time the write method works fine, but after
>it writes the first file, any files after that makes it throw a
>nullpointerexception. No idea why. The problem is in the writeData
>method for sure.... why is it throwing null???
>
>Stack dump:
>08-10 23:04:43.309: WARN/dalvikvm(687): threadid=17: thread exiting
>with uncaught exception (group=0x4000fe70)
>08-10 23:04:43.319: ERROR/AndroidRuntime(687): Uncaught handler:
>thread IntentService[TheDaemon] exiting due to uncaught exception
>08-10 23:04:43.357: ERROR/AndroidRuntime(687):
>java.lang.NullPointerException
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>org.myApp.ThePreferences.writeData(ThePreferences.java:39)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>org.myApp.ThePhone.savePhoneToDisk(ThePhone.java:33)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>org.myApp.ThePhone.refreshStatus(ThePhone.java:82)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>org.myApp.TheDaemon.onHandleIntent(TheDaemon.java:62)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>android.app.IntentService$ServiceHandler.handleMessage
>(IntentService.java:29)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>android.os.Handler.dispatchMessage(Handler.java:99)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>android.os.Looper.loop(Looper.java:123)
>08-10 23:04:43.357: ERROR/AndroidRuntime(687): at
>android.os.HandlerThread.run(HandlerThread.java:60)
>
>
>
>write Method
>
>public boolean writeData(String filename, String contents)
> {
> try {
> FileOutputStream fOut =
>context.openFileOutput(filename,
>Context.MODE_PRIVATE);
> OutputStreamWriter osw = new OutputStreamWriter(fOut);
> osw.write(contents);
> osw.flush();
> osw.close();
> } catch (IOException e) {
> e.printStackTrace();
> Log.e("fmi", "fmi throws ioexception in WRITER");
> return false;
> } catch (java.lang.NullPointerException e) {
> e.printStackTrace();
> }
> return true;
> }
>
>Any idea why it's throwing a null pointer exception?
>
--
jason.software.particle
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---