Hi everyone,
Could somebody please help me out with this problem :
I am trying to load a .jpg image into an Imageview with the standard code : ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirInternal, Image, ImageView1.Width, ImageView1.Height, True))
In testing It works fine if the .jpg file is in DirAssets , but since I need to download the file first , it can't be placed in DirAssets so I download to DirInternal.
But I can't seem to get it to work, I keep getting file not found error. I put in all the read/write permissions in the Main module, just to be on the safe side, but still it won't work.
I check if the file exists and I get true, but still nothing.
Do I need to open an InputStream to fetch a file from DirInternal ?
Here is the code :
Line 28 is where the the code searches for the file in DirInternal
[/CODE]
And here is the log :
icon downloaded ok
Icon file is found <----------------------here I log if the file exists in DirInternal.
northerngas.jpg <----------------------here I log the file name in DirInternal just to be sure.
** Activity (selectscreen) Pause, UserClosed = false **
** Activity (billlist) Create, isFirst = true **
DB size is:3
billlist_createitem (java line: 715)
java.io.FileNotFoundException: /data/user/0/simbills.beta/files/northerngas.jpg (No such file or directory) <------------------------ here the same file is not found
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:214)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.initializeSampleImpl(CanvasWrapper.java:601)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeResize(CanvasWrapper.java:548)
at anywheresoftware.b4a.keywords.Common.LoadBitmapResize(Common.java:1371)
at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.LoadBitmapResize(B4XViewWrapper.java:674)
at simbills.beta.billlist._createitem(billlist.java:715)
at simbills.beta.billlist._activity_create(billlist.java:424)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at simbills.beta.billlist.afterFirstLayout(billlist.java:104)
at simbills.beta.billlist.access$000(billlist.java:17)
at simbills.beta.billlist$WaitForLayout.run(billlist.java:82)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
--------- beginning of crash
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Could somebody please help me out with this problem :
I am trying to load a .jpg image into an Imageview with the standard code : ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirInternal, Image, ImageView1.Width, ImageView1.Height, True))
In testing It works fine if the .jpg file is in DirAssets , but since I need to download the file first , it can't be placed in DirAssets so I download to DirInternal.
But I can't seem to get it to work, I keep getting file not found error. I put in all the read/write permissions in the Main module, just to be on the safe side, but still it won't work.
I check if the file exists and I get true, but still nothing.
Do I need to open an InputStream to fetch a file from DirInternal ?
Here is the code :
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
CallSub (Starter, "DataBaseSize")
Activity.LoadLayout("1")
'Activity.AddMenuItem3("", "refresh", xui.LoadBitmapResize(File.DirAssets, "ic_cached_white_24dp.png", 32dip, 32dip, True), True)
'Activity.AddMenuItem3("", "done", xui.LoadBitmapResize(File.DirAssets, "ic_done_white_24dp.png", 32dip, 32dip, True), True)
'Dim bitmaps As List = Array("eni-logo-vector.png", "F1 ENEL.png", _
' "F3 SKY.png", "nuovo-logo-tim-.jpg","tkair.jpg","DD.jpg")
Private dbsize As Int
dbsize = Starter.IDHolder.Size
PanelHolder= -1
Dim LocExp As String
Dim LocComp As String
Dim LocAmount As String
Dim LocCur As String
Dim LocLogo As String
Dim LocButton As Int
For i = 0 To dbsize-1
LocExp = Starter.Expiry2holder.Get(i)
LocComp = Starter.Companydueholder.Get(i)
LocAmount =Starter.AmountHolder.Get(i)
LocCur = "€"
LocLogo = Starter.Companydueholder.Get(i) & ".jpg"
LocButton = i
CLV1.Add(CreateItem(CLV1.AsView.Width, LocComp, LocLogo, LocCur, LocAmount, LocExp, LocButton), "")
Next
End Sub
Line 28 is where the the code searches for the file in DirInternal
B4X:
[CODE=b4x]Private Sub CreateItem(Width As Int, Title As String,Image As String,Cur As String, Tot As String, ary As String, PaidButton As String) As Panel
' GetData
Dim p As B4XView = xui.CreatePanel("")
Dim height As Int = 180dip
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 150dip
p.SetLayoutAnimated(0, 0, 0, Width, height)
p.LoadLayout("Card1")
'p.SetColorandBorder(xui.Color_RGB(58,101,114),5dip,xui.Color_White ,7dip)
'p.Width =20dip
p.Tag= False
lblExp.Text = ary
lblContent.Text = Title
Label1.Text = Cur
Label3.Text = Tot
ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirInternal, Image, ImageView1.Width, ImageView1.Height, True)) [COLOR=rgb(184, 49, 47)] [/COLOR]
Return p
End Sub
And here is the log :
icon downloaded ok
Icon file is found <----------------------here I log if the file exists in DirInternal.
northerngas.jpg <----------------------here I log the file name in DirInternal just to be sure.
** Activity (selectscreen) Pause, UserClosed = false **
** Activity (billlist) Create, isFirst = true **
DB size is:3
billlist_createitem (java line: 715)
java.io.FileNotFoundException: /data/user/0/simbills.beta/files/northerngas.jpg (No such file or directory) <------------------------ here the same file is not found
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:214)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.initializeSampleImpl(CanvasWrapper.java:601)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeResize(CanvasWrapper.java:548)
at anywheresoftware.b4a.keywords.Common.LoadBitmapResize(Common.java:1371)
at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.LoadBitmapResize(B4XViewWrapper.java:674)
at simbills.beta.billlist._createitem(billlist.java:715)
at simbills.beta.billlist._activity_create(billlist.java:424)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at simbills.beta.billlist.afterFirstLayout(billlist.java:104)
at simbills.beta.billlist.access$000(billlist.java:17)
at simbills.beta.billlist$WaitForLayout.run(billlist.java:82)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
--------- beginning of crash
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **