I've seen this error in other posts but I think their details are not quite the same. I hope this one is fairly simple, but it's stumped me.
My application worked fine until I installed B4A on a newer PC along with all the additional requirements and recompiled on the new machine. The application compiles file but I now get a "File not found" runtime error when I try to load my text. This happens on the emulator as well as my Android tablet. I can see the text file in question in my Files folder on the PC (File.DirAssets) and have renamed it as simply as possible (data.txt) to avoid uppercase/lowercase issues but I still get the error.
As far as I can see, the only thing that's different between the two PCs is that Java etc are installed on the new PC on Drive I, not C. However, if the file paths were wrong, shouldn't the app fail to compile? I can't see any options for setting application paths other than the obvious ones in Tools | Configure Paths.
Here is some of my code.
My application worked fine until I installed B4A on a newer PC along with all the additional requirements and recompiled on the new machine. The application compiles file but I now get a "File not found" runtime error when I try to load my text. This happens on the emulator as well as my Android tablet. I can see the text file in question in my Files folder on the PC (File.DirAssets) and have renamed it as simply as possible (data.txt) to avoid uppercase/lowercase issues but I still get the error.
As far as I can see, the only thing that's different between the two PCs is that Java etc are installed on the new PC on Drive I, not C. However, if the file paths were wrong, shouldn't the app fail to compile? I can't see any options for setting application paths other than the obvious ones in Tools | Configure Paths.
Here is some of my code.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim RCount As Int, N As Int, SU As StringUtils, OurList As List, X As Int, S() As String
' Load file created with Visual Designer
Activity.LoadLayout("DiaryMain")
BFBtn.Text = "Browse recent"
StatusLbl.Text = "Ready"
SrchBtn.Enabled = True
Try
'DBFilename is defined in module G (Global variables)
G.SQL1.Initialize(G.DBFileDir, G.DBFileName, True)
RCount = G.SQL1.ExecQuerySingleResult("Select count(*) from DEntries")
StatusLbl.Text = RCount & " entries in diary"
Catch
StatusLbl.Text = "No database found. Use IMPORT to create it."
End Try
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub CopyFileFromAssets (FileName As String) As String ' Note: this will overwrite without prompting
Dim TargetDir As String = File.DirRootExternal
If File.Exists(TargetDir, FileName) Then
File.Delete(TargetDir, FileName)
End If
Try
' File.DirAssets is the Files folder within our app. Is read-only - that is, we can't delete
File.Copy(File.DirAssets, FileName, TargetDir, FileName)
Return TargetDir
' Delete the source file to save space
'File.Delete(File.DirAssets, FileName)
'MsgboxAsync("Deleted file " & FileName & " from " & File.DirAssets, G.AppName)
Catch
MsgboxAsync("Error! File " & FileName & " not found in folder " & File.DirAssets, G.AppName)
End Try
End Sub
Sub SrchBtn_Click
StartActivity("Search")
End Sub
Sub ImpBtn_Click
Dim N As Int, OurLoc As String, SU As StringUtils, OurList As List, X As Int, Recd() As String
G.TFName = "data.txt" ' This name is CASE SENSITIVE so keep it simple!
'NOTE brackets after S, denoting this is a string ARRAY
' Create database if this does not already exist
StatusLbl.Text = "Importing data. Please wait..."
StatusLbl.Invalidate ' Force redraw
OurLoc = CopyFileFromAssets(G.TFName) 'Get data file from assets