W Walt Member Feb 15, 2017 #1 TR.Initialize(File.OpenInput(f,"")) Do While line <> Null line = TR.ReadLine If line = Null Then Exit WriteTextArea Loop TR.Close End Sub Sub WriteTextArea It looks totally redundant to me but without it the Do While loop try's to take too many lines and I get this error: java.lang.NullPointerException
TR.Initialize(File.OpenInput(f,"")) Do While line <> Null line = TR.ReadLine If line = Null Then Exit WriteTextArea Loop TR.Close End Sub Sub WriteTextArea It looks totally redundant to me but without it the Do While loop try's to take too many lines and I get this error: java.lang.NullPointerException
W Walt Member Feb 15, 2017 #2 Okay, in response to my own question, the do-loop tests at the beginning. By then, it's too late, the null value has already been passed to WriteTextArea and caused the error. Still, it seems there should be a tidier way to do that. Upvote 0
Okay, in response to my own question, the do-loop tests at the beginning. By then, it's too late, the null value has already been passed to WriteTextArea and caused the error. Still, it seems there should be a tidier way to do that.
Erel B4X founder Staff member Licensed User Longtime User Feb 15, 2017 #3 Avoid using TextReader and TextWriter. If you want to handle the text line by line: B4X: For Each line As String in File.ReadList(f, "") ... Next If you want to read the complete text: B4X: Dim s As String = File.ReadString(...) Upvote 0
Avoid using TextReader and TextWriter. If you want to handle the text line by line: B4X: For Each line As String in File.ReadList(f, "") ... Next If you want to read the complete text: B4X: Dim s As String = File.ReadString(...)