Android Question Exporting data from B4XTable to .csv file

TonyVerberne

Member
Licensed User
Longtime User
I am trying to export records in my table to a .csv file that can then be read into Excel.
I have attached a zip file of the project.

When I press the 'Export' button the app crashes;

Here is the error log report:
Logger connected to: Google Pixel
--------- beginning of main
Copying updated assets files (20)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
Sleep not resumed (context is paused): anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub
Sleep not resumed (context is paused): anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
Permission granted
** Activity (main) Resume **
Index time: 26 ms (96 Items)
Error occurred on line: 158 (EditableTable)
java.io.FileNotFoundException: /data/user/0/b4a.CheeseDiary/files/virtual_assets/table.csv: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileInputStream.<init>(FileInputStream.java:159)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:204)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:340)
at b4a.CheeseDiary.editabletable._button1_click(editabletable.java:551)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7140)
at android.view.View.performClickInternal(View.java:7117)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27351)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 23 more

Any help is appreciated.
 

Attachments

  • CheeseDiary.zip
    11.2 KB · Views: 308

DonManfred

Expert
Licensed User
Longtime User
java.io.FileNotFoundException: /data/user/0/b4a.CheeseDiary/files/virtual_assets/table.csv: open failed: ENOENT (No such file or directory)
i did not check your code but: Are you trying to save the csv to File.DirAssets? DirAssets is READONLY
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
change the button sub...

B4X:
Sub Button1_Click
    ExportTableToCSV
    'If File.Exists(File.DirDefaultExternal, "table.csv") = False Then
    'File.Copy(File.DirAssets, "table.csv", File.DirDefaultExternal, "table.csv") ' as the file does not exists in assets it can not be copied...
    'End If
End Sub
 
Upvote 0

TonyVerberne

Member
Licensed User
Longtime User
Thanks DonManfred. Yes I realise that File.DirAssets is read only and not accessible. I am trying to read from a file that it is in the DirAssets folder and save it as a .csv file in the DirDefaultExternal folder. In that way, users of the app will be able to save their records (of cheeses that they have made, a noble thing) prior to any app updates or enhancements.
Tony Verberne
 
Upvote 0

TonyVerberne

Member
Licensed User
Longtime User
Thank you for your reply Erel. I listened to the Runtime Permissions tutorial and it is clear that using File.DirInternal is not a good idea.

It is good that Files in File.DirInternal are not erased during updates. Nevertheless, if I wanted to export the data in the CSVfile to Excel, how is that done safely?
That's really what I am trying to do.
 
Upvote 0

TonyVerberne

Member
Licensed User
Longtime User
Sorry Erel, I meant 'File.DirDefaultExternal'.

I had better explain myself more clearly. If I go to my phone's storage folder and drill down to 'storage/android' I can't see the data that I have stored in the diary (because it is located in DirAssets?).
I would like to have a way to export the data (in this case, records of cheeses that I, and my artisanal home cheesemaker colleagues, make and record. Ideally, when 'Export' is clicked Excel opens and the file can be saved in some location. Thanks for your help as always and I apologise if I appear obtuse.
 
Upvote 0
Top