Android Question EMFILE too many files open error

EvgenyB4A

Active Member
Licensed User
Longtime User
My Application display HTML pages from DirRootExternal that contains GIF file every 30 sec . After some hours of running in debug mode, I have got " ...EMFILE (Too many file open)" error. Please look at uploaded file. What maybe the reasons?
The sub for display:


Dim o AsReflector

WebView1.ZoomEnabled=False

'

IfintGif<1ThenintGif=1

IfintGif>GetClipCount ThenintGif=1

o.Target =
WebView1

o.RunMethod2(
"clearCache","True","java.lang.boolean")

WebView1.LoadUrl("file://" & File.Combine(File.DirRootExternal & "/Adverts", "clip" & intGif & ".htm"))

intGif=intGif+1
 

Attachments

  • android-error.JPG
    android-error.JPG
    316.6 KB · Views: 215

EvgenyB4A

Active Member
Licensed User
Longtime User
Can you post the JobDone code?
The relevant JobName here is "CheckDF":


Sub
JobDone(Job AsHttpJob)

Dim
resultString AsString

Try

SelectCase Job.JobName

Case"CheckDF"
If Job.Success Then

resultString =Job.GetString
Log(resultString)

Ifsf.InString( resultString,"none")<0Then

strRespDown="Yes"' '"Yes"

'resultString = "zzz" '"zip###images###010101010.zip"

Dim s() AsString = Regex.Split("###",resultString) 'resultString

If s.Length >= 3Then

FileBase = s(0)

Dim FilesType AsString = s(1)

Dim FileName AsString = s(2)

SelectCaseFileBase's(0)

Case"zip"

SetForDownload
DownloadZipFile(
mdlCode.strLinkToServer & "/files/"&FileName, FilesType, FileName) 'resultString

Case"apk"

SetForDownload
DownloadAPKFile(
mdlCode.strLinkToServer & "/files/"&FileName, FilesType, FileName) 'resultString

EndSelect
EndIf
Else

mdlCode.strResetTime =resultString.Replace("none","")

IfmdlCode.strResetTime = ""ThenmdlCode.strResetTime = "23:45:00"

EndIf

EndIf

Case"CheckingCard"

myProgressDialog.Hide

CardSwiped = False

If Job.Success Then

resultString =Job.GetString
CardInfo(resultString)
Buzzer(
1)

IfpnlNum0.Visible = TrueThen

intTimeAdv=0

pnlNum0.Visible=False

UserProductsReset
pnlNum1.Visible=True

EndIf

Else

'mdlCode.blnCrediCardSw =False

mdlCode.Track2=""
CardSwiped = False

mdlCode.Credit = 0

lblCredit.Text = "0.00"

lblSwipeCard.Text="נא להעביר כרטיס"

mdlCode.Credit=0

mdlCode.strCardCredit="0.00"

mdlCode.blnCrediCardSw=False

Toast.Initialize(Activity, Me, Activity.Height, Activity.Width)

Toast.ToastMessageShow2("אין תקשורת עם שרת! ", 3, 50, 50, "", Colors.Yellow, Colors.Red, 30, True)

Buzzer(
3)

EndIf

EndSelect
Catch

End
Try

Job.Release

BootStart
.NetworkFree = True

End Sub
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
Ok. Now i use it:

B4X:
Sub
JobDone(Job AsHttpJob)
Dim
resultString AsString
Try
SelectCase Job.JobName
Case"CheckDF"
If Job.Success Then
resultString =Job.GetString
Log(resultString)
Ifsf.InString( resultString,"none")<0Then
strRespDown="Yes"' '"Yes"
'resultString = "zzz" '"zip###images###010101010.zip"
Dim s() AsString = Regex.Split("###",resultString) 'resultString
If s.Length >= 3Then
FileBase = s(0)
Dim FilesType AsString = s(1)
Dim FileName AsString = s(2)
SelectCaseFileBase's(0)
Case"zip"
SetForDownload
DownloadZipFile(
mdlCode.strLinkToServer & "/files/"&FileName, FilesType, FileName) 'resultString
Case"apk"
SetForDownload
DownloadAPKFile(
mdlCode.strLinkToServer & "/files/"&FileName, FilesType, FileName) 'resultString
EndSelect
EndIf
Else
mdlCode.strResetTime =resultString.Replace("none","")
IfmdlCode.strResetTime = ""ThenmdlCode.strResetTime = "23:45:00"
EndIf
EndIf
Case"CheckingCard"
myProgressDialog.Hide
CardSwiped = False
If Job.Success Then
resultString =Job.GetString
CardInfo(resultString)
Buzzer(
1)
IfpnlNum0.Visible = TrueThen
intTimeAdv=0
pnlNum0.Visible=False
UserProductsReset
pnlNum1.Visible=True
EndIf
Else
'mdlCode.blnCrediCardSw =False
mdlCode.Track2=""
CardSwiped = False
mdlCode.Credit = 0
lblCredit.Text = "0.00"
lblSwipeCard.Text="נא להעביר כרטיס"
mdlCode.Credit=0
mdlCode.strCardCredit="0.00"
mdlCode.blnCrediCardSw=False
Toast.Initialize(Activity, Me, Activity.Height, Activity.Width)
Toast.ToastMessageShow2("אין תקשורת עם שרת! ", 3, 50, 50, "", Colors.Yellow, Colors.Red, 30, True)
Buzzer(
3)
EndIf
EndSelect
Catch
End
Try
Job.Release
BootStart
.NetworkFree = True
End Sub
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
Where is the code that opens files? Are they later closed?
First time after restart runs the following code:
B4X:
Sub
InitProdBitmap
 
Dim b AsBitmap
 
Dim i AsInt
 
mdlCode.lstBitmap.Initialize
 
For i=1TomdlCode.intQ
 
IfFile.Exists(File.DirRootExternal&"/android/data/vend/" , mdlCode.strID(i).pic)Then
 
' Log(i & "-" & mdlCode.strID(i).pic)
 
b.InitializeSample(
File.DirRootExternal&"/android/data/vend/",mdlCode.strID(i).pic,200dip,200dip)
 
' mdlCode.lstBitmap.Initialize
 
mdlCode.lstBitmap.Add(b)
 
Else
 
Timer1.Enabled=False
 
Timer2.Enabled=False
 
Activity.Finish
 
StartActivity("Main")
 
EndIf
 
Next
 
End Sub
The number of picture files is 16 now.
The regular flow is: every 66 sec is http request(JobName = "CheckDF") and every 30 sec is Webview code to display adverts(see above).
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
I don't see the cause of this error in the code you posted. You will need to narrow it down. Disable one of the features (downloading or WebView) and decrease the timer interval to see where the error happens.
OK. I will try. Only one question:
Whether the B4A compiler invisibly close the file after File.Readstring, File.Writestring, InitializeSample, etc commands?
 
Upvote 0
Top