I am trying to save values in a string to a file on my local system by using the org.apache.commons.io.FileUtils static method writeStringToFile.
So, first I downloaded the commons-io-2.4.jar, along with its javadocs and source and imported it into my Eclipse project through the Java Build Path. Everything compiles just fine.
However, when I add the simple line:
org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File(Environment.getExternalStorageDirectory().toString() + "/logt.txt"), rslt.toString()); The program crashes. But, it doesn't crash anywhere near that statement. Instead, it crashes at the constructor of the Object which contains the method which calls this function.
In other words
- Earlier in my code I create an object TranslateTask,
- Which happens to contain a function call doTranslate().
- The writeStringToFile call is made within the doTranslate() call,
- However the actual crash takes place when I instantiate a TranslateTask object.
- But, when I comment out the call to writeStringToFile(), the crash never happens
- Even though the crash doesn't take place in the doTranslate() call...
- So, just the mere mention of writeStringToFile() makes my program crash when I instantiate an object which contains it.
To make it more eary, I instantiate the object within a Try, catch (RejectedExecutionException e) block but instead the program crashes at this part:
PathClassLoader.findClass(String) line: 243 **Last call in the stack** PathClassLoader(ClassLoader).loadClass(String, boolean) line: 573 PathClassLoader(ClassLoader).loadClass(String) line: 532 Translate$4.run() line: 159 **Crash happens here where I instantiate a TranslateTask object** So PathClassLoader... Not sure how to approach debugging this. All I know is that if I commend out the org.apache.commons.io.FileUtils.writeStringToFile() call, the error never happens and the code runs fine everywhere.
Running this on the API8/10 of Android, using Eclipse Indigo.
EDIT- Logcat:
08-07 18:40:11.409: I/System.out(1395): debugger has settled (1363)
08-07 18:40:14.399: W/KeyCharacterMap(1395): No keyboard for id 0
08-07 18:40:14.399: W/KeyCharacterMap(1395): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
Don't think it gives any hint, but this is all that logcat gives after the debugger has settled.
EDIT2 - For good measure, I just added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> But still no go
EDIT3 - I am starting to think the apache commons-io-2.4.jar doesn't work with Android inherently. Could that be it?
EDIT4 - In case anyone wants to take a crack at it, here is my code. It is made in Windows 7, Eclipse Indigo. The code is based on the "Hello Android" translate section. All I am trying to do is extract some JSON into a string and save it into my sdcard. But, it has evolved into this mystery here... https://dl.dropbox.com/u/10790286/Translate.zip (See TranslateTask.java line 111)
EDIT5 - Interesting update. When I manually put FileUtils.writeStringToFile(new java.io.File("/mnt/sdcard/logt.txt"), "test"); into the eclipse expressions box during a debug, I get the following error
An exception occurred: java.lang.NoSuchMethodError
I don't understand why I would get this error because 1) the WriteStringToFile() function is in the commons-io source. 2) I can instantiate a FileUtils object 3) I imported it into my program.
Whats going on here?