Android Question FILE NOT FOUND - ENOENT

Shadow&Max

Active Member
Licensed User
Longtime User
Now, this is REALLY weird! In debugging mode, I have both set to true. I test often and flush the apps data via Settings/Apps, so I start over often. This ONLY happens in the Release Modes, and it happens on emulators as well as actual devices...

#DebuggerForceStandardAssets: True
#DebuggerForceFullDeployment: True

Here's the error:



Now, the weird thing is that it happens once. Then I click on Yes, cancel my add/edit procedure, get back to my main app screen, try the thing again, and it works fine. Cancel again, try it again, and get the same error. Yes again (or even NO but No restarts he app), and fine, cancel out, try again, fine...

It's trying to get a file from DirAssets that IS one of the assets, but it's not even showing an attempted drive in that error message other that // and why would I be trying to access "//?"

This is a pain in the butt, because after I get past that first one, even if I save it after I've gotten the error, it never happens again. I's trying to get a graphic from DirAssets, and the whole thing is strange.

However, I HAVE to sole this before I release my app to testers...

Any suggestions???

HELLLPPPP! Thanks in advance!
 

Shadow&Max

Active Member
Licensed User
Longtime User
The code's been pretty stable for 3 months... it's something else. It triggers FIRST, the first time the file is ever attempted to be accessed and then good, and then bad... But once there's a record in the database in DirInternal, this never happens again, and I'm not storing anything in the initial setup file that runs on startup, or retrieving that data except until I try to get the first pic from Assets...

Here's the error:

** Activity (main) Pause, UserClosed = false **
** Activity (addedit) Create, isFirst = false **

** Activity (addedit) Resume **
java.io.FileNotFoundException: / / : open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:409)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:209)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeSample(CanvasWrapper.java:532)
at com.twodogapps.p2s.addedit._activity_resume(addedit.java:627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at com.twodogapps.p2s.addedit.afterFirstLayout(addedit.java:104)
at com.twodogapps.p2s.addedit.access$100(addedit.java:16)
at com.twodogapps.p2s.addedit$WaitForLayout.run(addedit.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:393)
... 20 more
java.io.FileNotFoundException: / / : open failed: ENOENT (No such file or directory)
** Activity (main) Create, isFirst = true **

Here's the code that I'm sure is causing this the first time that file is accessed:

B4X:
Sub SetBlankPic
    iv.Bitmap = LoadBitmap(File.DirAssets,"blank2.png")
    ResizePhoto(File.DirAssets,"blank2.png")
    osizeh = iv.Height
    osizew = iv.Width
    osizet  = iv.Top
    osizel = iv.Left
    TurnOnBlankButtons
    iv.Visible = True
End Sub

ResizePhoto is working fine and TurnOnBlankButtons is innocuous. It's that blank2.png it's trying to find. And, I know it's there or the pic wouldn't show up afterwards or in other places in the code... But this one errors, when I say yes to the error, it continues and the buttons that were turned on are there, just NOT that image! And this ONLY happens in the beginning!!!

FYI:

Private iv As ImageView is in Globals and has been stable for months.
Dim osizeh, osizew, osizet, osizel As Int are also in Globals. Another FYI, the error system is reporting those as unused variables that are never assigned a value but clearly are in the code.
 
Last edited:
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
What does ResizePhoto() do? I noticed you are passing the file to the function instead of the bitmap. Possibly it is deleting, then recreating it every other call?
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Here's the code for ResizePhoto. This is used every time a picture is added from the gallery or a picture is taken, and it gets the dimensions of the pic, and resizes the pic to fit into the ImageView, iv. This is because the picture size changes based on device orientation and original dimensions of the pic chosen, so the proportions displayed are correct.

B4X:
Sub ResizePhoto (Dir As String, FileName As String)
    b.InitializeSample(Dir, FileName, pnl.Width, pnl.Height)
    hip = b.Height
    wip = b.Width
        If hip > wip Then 'It's Portrait
            imageratio = (wip / hip)
            'Size iv
            iv.Top = 10dip
            iv.Height = pnl.Height - 20dip
            iv.Width = iv.Height  * imageratio  '- 20dip
            iv.Left = (pnl.Width / 2) - (iv.Width / 2) - 10dip
        Else 'It's Landscape
            imageratio = (hip / wip)
            'Size iv
            iv.Width = pnl.Width - 40dip
            iv.Height = iv.Width * imageratio
            iv.Top = (pnl.Height / 2) - (iv.Height / 2)
            iv.Left = 20dip
        End If
       
    DelPic.Top = iv.Top + 6dip
    EditPic.Top = DelPic.Top
    EditPic.Left = iv.Left + iv.Width - DelPic.Width - 6dip   
    DelPic.Left = iv.Left + 6dip
   
End Sub
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
The stack trace you posted seems odd. I see no reference to SetBlankPic nor LoadBitmap(). I do see a reference to CanvasWrapper$BitmapWrapper.InitializeSample, but it should be CanvasWrapper$BitmapWrapper.Initialize if it is being called from within LoadBitmap(). Are you making any calls to InitializeSample() other than in ResizePhoto()? Somewhere within Activity_Resume?
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Yes, it's called several times but all in different situations. But I'll track them and see if I can find where they're being hit and if being hit at the wrong times.
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
Unfortunately, you can't set breakpoints in release mode, but you can use Log() to track what your code is doing at various points. One thing to try is putting Log("--Entering Sub MySub") and Log("--Exiting Sub MySub") at the start and end of each subroutine so you will know which one it is in when the error occurs. Also, any function calls you might suspect, you can place Log("--Calling ThisFunction"), Log("--Called ThisFunction") to determine if it is the actual problem.

for example, you can change the above Sub like so.
B4X:
Sub SetBlankPic
Log("--Entering Sub SetBlankPic")
Log("--Calling LoadBitmap")
 iv.Bitmap = LoadBitmap(File.DirAssets,"blank2.png")
Log("--Called LoadBitmap")
 ResizePhoto(File.DirAssets,"blank2.png")
 osizeh = iv.Height
 osizew = iv.Width
 osizet = iv.Top
 osizel = iv.Left
 TurnOnBlankButtons
 iv.Visible = True
Log("--Exiting Sub SetBlankPic")
End Sub

Might make narrowing down the actual problem much easier.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Right...
In some cases i also print the complete sub-call to the log too to see "what exactly i´m calling here" (or in the sub i´m calling i do logs about which parameters and which values the parameter have

B4X:
Log("ftp.UploadFile("&GetParentPath(f.Replace(ftpdest,root))&", "&GetFilename(f)&", "&GetParentPath(f.Replace(root,ftpdest))&"/"&")")
FTP.UploadFile(GetParentPath(f.Replace(ftpdest,root)),GetFilename(f),False, GetParentPath(f.Replace(root,ftpdest))&"/"&GetFilename(f))
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Thanks James... Yea, I know... What I'm trying to figure out is what I changed that killed this... none of that code has changed in months, and it's never given me a problem before. I screwed something up today I think, but not sure what... Thanks for the Log ideas... I do know how to use them... Just sort of pain...I'm trying to see if I can trigger it in debug mode now... would be much easier to find it if I can stay in debug and have it pop up...
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Thanks too Manfred!
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Update... Somehow, it cleared it self up. Of course, that makes me very uncomfortable, but at least it's working, even from a clean install... I didn't change and of the calls, just tinkered a bit with other stuff, and the next time I tried it, it worked...

Go figure! Thanks for all the replies guys... really appreciated.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…