Error runing sample code

aklisiewicz

Active Member
Licensed User
Longtime User
I'm trying to implement reading a txt document. I have found the sample code and modified the Filename to filename I have. When compiling - no errors, but when I try to open this file I get "File Not Found' ERROR!

I added the file to the File in IDE, but it still doesn't work

This "Main.DBFileDir" is defined in Main module, so the path should be available everywhere. When I'm reading the path right before Initialize() it shows wired location (see attachment). Is this where the file should reside ?

------------------------------------------------------------------------
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Intro")
    Reader.Initialize(File.OpenInput(Main.DBFileDir, "edb_intro.txt"))
    Line = Reader.ReadLine
    Do While Line<>Null
        Log(Line)
        Line = Reader.ReadLine
    Loop
    Reader.Close
End Sub
any ideas what is wrong here ?
Arthur
 

Attachments

  • Error_01.jpg
    Error_01.jpg
    11.5 KB · Views: 133
Last edited:

aklisiewicz

Active Member
Licensed User
Longtime User
well, when I start program and test for Path the variable has the same value (as on the attached image). I'm not sure where is it taking the path, or where is is initialized. Basically the only thing I have in Main module is this:

Dim DBFileDir As String :DBFileDir = File.DirInternal
Dim DBFileDirEx As String :DBFileDirEx = File.DirDefaultExternal

here is the code:
B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim SQL1 As SQL
    Dim MediaPlayer1 As MediaPlayer
    Dim timer1 As Timer
    '----------------------------Start SQLite--------------------------------------------------------------------------------------------------
    Dim DBFileName As String                 :DBFileName = "edbmo.db3"
    Dim DBTableName As String               :DBTableName = "issues"
    Dim DBFileDir As String                        :DBFileDir = File.DirInternal
    Dim DBFileDirEx As String                   :DBFileDirEx = File.DirDefaultExternal
    '------------------------------End SQLite -----------------------------------------------------------------------------------------------
    Dim IssueID As Int
    Dim ProductID As Int
    
End Sub
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim btnIntro As Button
    Dim btnAudio As Button
    Dim btnIssues As Button
    Dim btnProducts As Button
    Dim btnDocuments As Button
    '-----------------------------Start Audio Player -----------------------------------------------------------------------------------------
    Dim barPosition As SeekBar
    Dim barVolume As SeekBar
    Dim lblPosition As Label
    Dim Looping As ToggleButton
    '-----------------------------End Audio Player -----------------------------------------------------------------------------------------

End Sub
Sub Activity_Create(FirstTime As Boolean)

    File.Delete(File.DirDefaultExternal, DBFileName)    ' for testing
    'Copy and Initialize database
    If File.Exists(File.DirDefaultExternal, DBFileName) = False Then
        DBFileDir = DBUtils.CopyDBFromAssets(DBFileName)
    End If
    SQL1.Initialize(DBFileDir, DBFileName, True)
    Activity.LoadLayout("Main")                                        ' Loads "Main" layout file
    'Msgbox(DBFileDir,"Path Info")
End Sub

Sub btnIssues_Click
    If btnIssues.Text="Issues" Then
        'Msgbox("Issues Selected","INFO")
        StartActivity(IssueList)
    End If        
End Sub
Sub btnAudio_Click
    If btnAudio.Text="Audio" Then
        StartActivity(AudioPlayer)
    End If
End Sub

Sub btnProducts_Click
    If btnProducts.Text="Products" Then
        StartActivity(ProductList)
    End If
End Sub

Sub btnIntro_Click
    If btnIntro.Text="Introduction to Essential Oils" Then
        StartActivity(Intro)
    End If
End Sub

Sub btnDocuments_Click
    If btnDocuments.Text="Documents" Then
        StartActivity(Documents)
    End If
End Sub
and here is the code to display TXT file

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Reader As TextReader
    Dim Line As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Intro")
    Msgbox(Main.DBFileDir,"Info")    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub LoadIntro(Dir As String, FileName As String)
Reader.Initialize(File.OpenInput(Main.DBFileDir, "edbintro.txt"))
    Line = Reader.ReadLine
    Do While Line<>Null
        Log(Line)
        Line = Reader.ReadLine
    Loop
    Reader.Close
End Sub
 
Upvote 0
Top