im using this code to "backup" a realm database on first run:
try {
FileUtils.copyFile(new File(realm.getPath()), new File(Environment.getExternalStorageDirectory()+"/old_db.realm"));
} catch (IOException e) {
e.printStackTrace();
}
and i receive this error and APP CRASH
java.lang.ExceptionInInitializerError
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1150)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1091)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)
at com.leifacil.vademecum.Atividades.Splash.onCreate(Splash.java:118)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.access$700(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org.apache.commons.io.output.StringBuilderWriter
at org.apache.commons.io.IOUtils.<clinit>(IOUtils.java:117)
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1150)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1091)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)
at com.leifacil.vademecum.Atividades.Splash.onCreate(Splash.java:118)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.access$700(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
the worst thing? ITS WORKING, its correctly copyingthe file and save at the ExternalStorage.... why worst? dont know the reason to crash -_-
ps: i use commons.io and FileUtils in other files, maybe it will crash too
SOLVED:
Missing this at the Application in Manifest
android:name="android.support.multidex.MultiDexApplication"
PS: without it works perfectly for Android 6.0(api 24)
the problem was in the Android 4.1.2 (API 16)
where i found the answer: