File.DirAssets question

Shaun

Member
Licensed User
Longtime User
Hi,

I am trying to load an image in to a panel. When a button is pushed, the image appears on the panel, simple enough.

B4X:
   Dim bg As BitmapDrawable
   bg.Initialize(LoadBitmap(File.DirAssets, "cam0077.jpg"))
   bg.Gravity = Gravity.FILL
   pnlImages.Background = bg

It compiles fine, but when I run it, I get a directory or file not found error:
java.io.FileNotFoundException: /C:\Users\Shaun\Documents\b4a\interfacestuff\Files/cam0077.jpg: open failed: ENOENT (No such file or directory)

The file is in the correct directory. Any clue why I am getting this errror?

Thanks
 

wheretheidivides

Active Member
Licensed User
Longtime User
This you import it from IDE. click on files at bottom right and then add files? It will import into assets.

Dim IV1 as ImageView

IV1.Bitmap = LoadBitmap(File.DirAssets, "cam0077.jpg"))
 
Upvote 0

Shaun

Member
Licensed User
Longtime User
This you import it from IDE. click on files at bottom right and then add files? It will import into assets.

Dim IV1 as ImageView

IV1.Bitmap = LoadBitmap(File.DirAssets, "cam0077.jpg"))

Yes, it is imported from the IDE. No matter what I do I get a 'file not found exception'.

What could be causing this? Could it be the file type?
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Shaun.. Just to be sure .. maybe check and remove jpg from assets list then re add it to the file assets list.

Failing that can u upload project, File > Export as Zip.

Cheers mj
 
Upvote 0

Shaun

Member
Licensed User
Longtime User
I got it to work. I added an imageView. I was still getting the error loading it into the imageView, so in the designer view I set the image file property of the ImageView to my image.

After doing that the file not found error went away and the image showed.

Thanks for all your help!

-Shaun
 
Last edited:
Upvote 0

Shaun

Member
Licensed User
Longtime User
OK, I got the error again once I wrote code to make the image appear when I clicked the button. I figured out what was wrong. There was something about the file that it did not like. I loaded a different file that had dashes in it, and still got the error. I took the dashes out, and it loaded as I wanted it to.

This:
imgVirw1.Bitmap = LoadBitmap(File.DirAssets, "mypicture.jpg")

Worked.

Thanks again.
 
Upvote 0
Top