Android Question [Solved] Getting errors although the code work (at least I think so!)

opus

Active Member
Licensed User
Longtime User
I'm trying to get my 5year old b4a project into the actual IDE (Version 10).
I got it running on a tablet connected via the B4A Bridge again, however I'm recieving Errors which I can't understand:

[CODE lang="b4x" title="Error"]Error occurred on line: 50 (clKarte)
java.io.FileNotFoundException: /data/data/Opus.Patience/files/virtual_assets/kreuz1: open failed: ENOENT (No such file or directory)[/CODE]

[CODE lang="b4x" title="Code from clKarte" highlight="37"]Public Sub Initialize(i As Int)
Dim k As Int 'KartenWert-Counter
Dim l As Int 'KartenSymbol-Counter
Dim m As Int 'KartenSet-Counter
Dim BitmapDrawable1 As BitmapDrawable
'Hier wird eine Karte erstellt.
'Anhand der übergebenen Zahl wird Kartenwert, das Symbol und Rücken gesetzt.
k=i Mod 13 'k imer 1 bis 13, also der Kartenwert!
l=i/13 'l immer 1 bis 4, ergibt das Symbol
If l>=4 Then
l=l-4
End If
If i>=52 Then 'sind die ersten 52 Karten gemacht (4*13), wird von vorne angefangen
m=1 'm sagt ob erstes Kartenblatt oder zweites!
End If
mWert=k+1
mSymbol=l
If l<2 Then
mFarbe=Allgemeines.Farbe.Schwarz
Else
mFarbe=Allgemeines.Farbe.rot
End If
BitmapDrawable1=Main.MyResources.GetApplicationDrawable("rueck" & (m+1))
mRueckBild=BitmapDrawable1.Bitmap
Dim temp As String 'enthält den Namen der Bilddatei!
Select mSymbol
Case Allgemeines.Symbol.Kreuz
temp = Allgemeines.constKreuz
Case Allgemeines.Symbol.Karo
temp = Allgemeines.constKaro
Case Allgemeines.Symbol.Herz
temp = Allgemeines.constHerz
Case Allgemeines.Symbol.Pik
temp = Allgemeines.constPik
End Select
If mWert <= 10 Then
temp =temp & mWert
Else
Select mWert
Case Allgemeines.kartenWert.Bube
temp = temp & Allgemeines.constBube
Case Allgemeines.kartenWert.Dame
temp = temp & Allgemeines.constDame
Case Allgemeines.kartenWert.Koenig
temp =temp & Allgemeines.constKoenig
End Select
End If
BitmapDrawable1=Main.MyResources.GetApplicationDrawable(temp)
mBild=BitmapDrawable1.Bitmap
'Hier wird die Größe der Kartenbilder gesetzt, XXXXX
mWidth = 80
mHeight = 112
mID=i
End Sub
[/CODE]
The line highlighted is line 50 in the complete class!

Why this error at this line? The app is seemingly (correct english word?) working as expected, so why this error at all? Before you ask, the file in question ("kreuz1" or Cross Ace ) is showing correctly in the app.
 
The error should be somewhere else.
In this piece of code there is no line that try to open that files.
And the file path looks strange to me, with /data/data.
More info are needed to be able to help you.
On which version of Android are you trying to run your code?
From Android 6+ is needed to request Permission to access certain directory.
 
Upvote 0
The error should be somewhere else.
That's what I think as well, thanks for answering!
The code line 48 would be the only one loading the file in question (in this one does work!).

I changed the manifest to

[CODE lang="b4x" title="Project manifest"]<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="28"/>[/CODE]

targetSdkVersion was 10.
I have set permissions to
android.permission.WRITE_EXTERNAL_STORAGE *

My actual test is on a Android 4.42 device.


Testing it longer it seems that this error is shown only after starting the app (once or twice).
 
Upvote 0
Can you check the exact path to your file?
Because it looks that it could be used the GetSafeDirDefaultExternal that does not need to request for Permission.
Can you show where you load that files?
Steps I suppose You need:
- enable the RuntimePermissions library
- add this to ProcessGlobals:
B4X:
Private rp As RuntimePermissions
- to access your files use (rp.GetSafeDirDefaultExternal("virtual_assets"), "Kreuz1") as filepath and filename.
 
Upvote 0
@Sagenut :
I've read the tutorial and wil check exactly that.
As of now I'm using the files from MyResources ( saved under ../jObects/res/drawble).
 
Upvote 0
Look at the Video Tutorial in the thread that @agraham gave you.
It's really explanatory.
 
Upvote 0
See Post #4
IT is not related to stringfunctipns. IT is related to the path to write to.
 
Last edited:
Upvote 0
Back
Top