Filippo Expert Licensed User Longtime User Sep 28, 2022 #1 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: Copy Type Applizenz(PurchaseTime As Long, PurchaseToken As String, Sku As String) Modul mAllg: B4X: Copy 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: Copy 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: *** Service (starter) Create *** Error occurred on line: 890 (mAllg) java.lang.RuntimeException: java.lang.ClassNotFoundException: fg.cronomillemiglia.clsinappbilling$_applizenz at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:314) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:374) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readMap(B4XSerializator.java:248) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:364) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:129) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadB4XObject(RandomAccessFile.java:340) at fg.cronomillemiglia.mallg._readmapasb4xobject(mallg.java:2211) at fg.cronomillemiglia.clsinappbilling3._readlizenzfile(clsinappbilling3.java:1554) at fg.cronomillemiglia.clsinappbilling3._getownedproductsoffline(clsinappbilling3.java:1524) at fg.cronomillemiglia.clsinappbilling3._initialize(clsinappbilling3.java:440) at fg.cronomillemiglia.starter._service_create(starter.java:1504) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146) at anywheresoftware.b4a.BA.raiseEvent(BA.java:193) at fg.cronomillemiglia.starter.onCreate(starter.java:56) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3342) at android.app.ActivityThread.-wrap4(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1680) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6518) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.ClassNotFoundException: fg.cronomillemiglia.clsinappbilling$_applizenz at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.lang.Class.forName(Class.java:378) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:583) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:291) ... 27 more Caused by: java.lang.ClassNotFoundException: Didn't find class "fg.cronomillemiglia.clsinappbilling$_applizenz" on path: DexPathList[[zip file "/data/app/fg.cronomillemiglia-sVbtZAWHHM9Wa59Pn9In2Q==/base.apk"],nativeLibraryDirectories=[/data/app/fg.cronomillemiglia-sVbtZAWHHM9Wa59Pn9In2Q==/lib/arm64, /system/lib64, /system/vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 32 more ** Service (starter) Start ** Click to expand...
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: Copy Type Applizenz(PurchaseTime As Long, PurchaseToken As String, Sku As String) Modul mAllg: B4X: Copy 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: Copy 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: *** Service (starter) Create *** Error occurred on line: 890 (mAllg) java.lang.RuntimeException: java.lang.ClassNotFoundException: fg.cronomillemiglia.clsinappbilling$_applizenz at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:314) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:374) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readMap(B4XSerializator.java:248) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:364) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:129) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadB4XObject(RandomAccessFile.java:340) at fg.cronomillemiglia.mallg._readmapasb4xobject(mallg.java:2211) at fg.cronomillemiglia.clsinappbilling3._readlizenzfile(clsinappbilling3.java:1554) at fg.cronomillemiglia.clsinappbilling3._getownedproductsoffline(clsinappbilling3.java:1524) at fg.cronomillemiglia.clsinappbilling3._initialize(clsinappbilling3.java:440) at fg.cronomillemiglia.starter._service_create(starter.java:1504) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146) at anywheresoftware.b4a.BA.raiseEvent(BA.java:193) at fg.cronomillemiglia.starter.onCreate(starter.java:56) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3342) at android.app.ActivityThread.-wrap4(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1680) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6518) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.ClassNotFoundException: fg.cronomillemiglia.clsinappbilling$_applizenz at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.lang.Class.forName(Class.java:378) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:583) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:291) ... 27 more Caused by: java.lang.ClassNotFoundException: Didn't find class "fg.cronomillemiglia.clsinappbilling$_applizenz" on path: DexPathList[[zip file "/data/app/fg.cronomillemiglia-sVbtZAWHHM9Wa59Pn9In2Q==/base.apk"],nativeLibraryDirectories=[/data/app/fg.cronomillemiglia-sVbtZAWHHM9Wa59Pn9In2Q==/lib/arm64, /system/lib64, /system/vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 32 more ** Service (starter) Start ** Click to expand...
DonManfred Expert Licensed User Longtime User Sep 28, 2022 #2 Filippo said: Where can the problem be? Click to expand... the new Classname. clsinappbilling -> clsinappbilling3 Upvote 0
Filippo said: Where can the problem be? Click to expand... the new Classname. clsinappbilling -> clsinappbilling3
Filippo Expert Licensed User Longtime User Sep 28, 2022 #3 DonManfred said: the new Classname. clsinappbilling -> clsinappbilling3 Click to expand... Why should it be a problem? I initialize the classe also with the new name. Upvote 0
DonManfred said: the new Classname. clsinappbilling -> clsinappbilling3 Click to expand... Why should it be a problem? I initialize the classe also with the new name.
agraham Expert Licensed User Longtime User Sep 28, 2022 #4 Have you tried cleaning the project? It looks like something doesn't know about the name change. Upvote 0
Filippo Expert Licensed User Longtime User Sep 28, 2022 #5 agraham said: Have you tried cleaning the project? It looks like something doesn't know about the name change. Click to expand... 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 said: Have you tried cleaning the project? It looks like something doesn't know about the name change. Click to expand... Yes, several times already. The compiler simply does not find the type "applizenz" anymore, although it is always in the same classe.
agraham Expert Licensed User Longtime User Sep 28, 2022 #6 What is this call. It is where the error actully occurs. What is mAllg and is it your code in ReadMapAsB4XObject mAllg.ReadMapAsB4XObject EDIT : Sorry = didn't read the code fragments carefully Upvote 0
What is this call. It is where the error actully occurs. What is mAllg and is it your code in ReadMapAsB4XObject mAllg.ReadMapAsB4XObject EDIT : Sorry = didn't read the code fragments carefully
agraham Expert Licensed User Longtime User Sep 28, 2022 #7 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
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.
Filippo Expert Licensed User Longtime User Sep 28, 2022 #8 agraham said: 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. Click to expand... 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 said: 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. Click to expand... Ok. That's what I thought, but I couldn't imagine the class name being stored in the file. Isn't that an error?
agraham Expert Licensed User Longtime User Sep 28, 2022 #9 Filippo said: Isn't that an error? Click to expand... 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 said: Isn't that an error? Click to expand... 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.
Filippo Expert Licensed User Longtime User Sep 28, 2022 #10 EDIT: Wrong again! I'm being too hasty tonight Click to expand... but try rewriting the file with the new class object and see if it fixes it. Click to expand... Unfortunately, this does not work for the user. I have to open the file first and check if a license is available. Upvote 0
EDIT: Wrong again! I'm being too hasty tonight Click to expand... but try rewriting the file with the new class object and see if it fixes it. Click to expand... Unfortunately, this does not work for the user. I have to open the file first and check if a license is available.
Filippo Expert Licensed User Longtime User Sep 28, 2022 #11 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
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.
Erel B4X founder Staff member Licensed User Longtime User Sep 29, 2022 #12 Tip: in the future you should use B4XSerializator directly: Code: Copy 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
Tip: in the future you should use B4XSerializator directly: Code: Copy 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.
Filippo Expert Licensed User Longtime User Sep 29, 2022 #13 Tip: in the future you should use B4XSerializator directly: Click to expand... Unfortunately, this is no longer possible with this app. With new app I already use it. Upvote 0
Tip: in the future you should use B4XSerializator directly: Click to expand... Unfortunately, this is no longer possible with this app. With new app I already use it.
Ronomega73 Member Licensed User Longtime User Nov 12, 2023 #14 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
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.