Android Question java.lang.ClassNotFoundException: de.xxxxxxxxxxxxx.clsinappbilling$_applizenz

Filippo

Expert
Licensed User
Longtime User
Hi,

I have a very strange error.

If I change the name of a classe, from clsinappbilling.bas to clsinappbilling3.bas, then the sub "ReadMapAsB4XObject" (the procedure is in a general module "mAllg") cannot read a file anymore, although the classe has not changed.
Where can the problem be?

The name "applizenz" is a type in the classe.
B4X:
    Type Applizenz(PurchaseTime As Long, PurchaseToken As String, Sku As String)

Modul mAllg:
B4X:
Public Sub ReadMapAsB4XObject(sDir As String, sFilename As String) As Map
    Dim raf As RandomAccessFile
    raf.Initialize2(sDir, sFilename, False, True)
    Dim mp As Map = raf.ReadB4XObject(raf.CurrentPosition)
    raf.Close
    Return mp
End Sub

In the classe the file is read with this procedure:
B4X:
Private Sub GetOwnedProductsOffline
    If File.Exists(File.DirInternal,"lizenz.mp") Then
        'Der Lizenz-File wird als B4XObject gespeichert
        ReadLizenzFile
    End If
End Sub

Private Sub ReadLizenzFile
    Dim lizenz As Applizenz
    Dim mp As Map
    mp.Initialize

   mp = mAllg.ReadMapAsB4XObject(File.DirInternal, "lizenz.mp")
End If

Error:
 

Filippo

Expert
Licensed User
Longtime User
Have you tried cleaning the project? It looks like something doesn't know about the name change.
Yes, several times already.
The compiler simply does not find the type "applizenz" anymore, although it is always in the same classe.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Ah! You are reading an object from a file that is already saved. The type of the saved object in the file is using the old class name as that is what it was saved as. You need to rewrite the file with the new class name. The class name is part of the type name.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Ok. That's what I thought, but I couldn't imagine the class name being stored in the file.

Isn't that an error?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Isn't that an error?
No. That's the way it works. You can have the same type name in different classes The actual type name includes its class name as that's how it works in Java

EDIT: Wrong again! I'm being too hasty tonight I think I am right but try rewriting the file with the new class object and see if it fixes it.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
EDIT: Wrong again! I'm being too hasty tonight


but try rewriting the file with the new class object and see if it fixes it.
Unfortunately, this does not work for the user.
I have to open the file first and check if a license is available.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
I have changed the classe name because of versioning.
Since the name change causes problems, so I created a b4xlib library from the classe.
Here you can change the version without problems.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: in the future you should use B4XSerializator directly:
B4X:
Public Sub ReadMapAsB4XObject(sDir As String, sFilename As String) As Map
    Dim ser 
    Return ser.ConvertObjectToBytes(File.ReadBytes(sDir, sFilename)
End Sub
The file format is a slightly different than RAF.WriteB4XObject / ReadB4XObject so you cannot change now.

The type name with the enclosing class is saved. Types declared in Main module or B4XMainPage can be used in apps with different package names.
 
Upvote 0

Ronomega73

Member
Licensed User
Longtime User
Hello! I'm not sure if this is still unsolved but I have just experienced the same problem while trying to fix another unrelated one. The Class Not Found error showed when I tried to transfer the type declaration from one module to the main activity module. When I moved back the type declaration to where it originally was the error went away. It seems that when you have already created an object of the same type and then later on move that type declaration somewhere else, using/referencing the said object will generate the Class Not Found error.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…