Writing to a file from an android widget, kotlin
I have a widget and a timer. When the timer goes off I update the widget and occasionally I would write some logs into file.
val fileOutputStream = FileOutputStream (fileName)
This line of code throws an exception.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.throughput, PID: 12123
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.io.FileNotFoundException: 1651309993702: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:575)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:125)
at com.example.throughput.ThroughputWidget.updateDisplay(ThroughputWidget.kt:106)
at com.example.throughput.ThroughputWidget.runnable$lambda-0(ThroughputWidget.kt:90)
at com.example.throughput.ThroughputWidget.$r8$lambda$SoLpIJoYOZc0Jp0ydNrhFhUczoI(Unknown Source:0)
at com.example.throughput.ThroughputWidget$$ExternalSyntheticLambda0.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7728)
at libcore.io.IoBridge.open(IoBridge.java:561)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:125)
at com.example.throughput.ThroughputWidget.updateDisplay(ThroughputWidget.kt:106)
at com.example.throughput.ThroughputWidget.runnable$lambda-0(ThroughputWidget.kt:90)
at com.example.throughput.ThroughputWidget.$r8$lambda$SoLpIJoYOZc0Jp0ydNrhFhUczoI(Unknown Source:0)
at com.example.throughput.ThroughputWidget$$ExternalSyntheticLambda0.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
What shall I ho to avoid the exception? When I looked for to com.example.throughput folder does not exist. Could it be the source of the issue?
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum