Android Question ClassNotFoundException after package name change

Inman

Well-Known Member
Licensed User
Longtime User
I had to change the package name of app after finishing a project. Now the compiled app generates an error during runtime

B4X:
java.lang.ClassNotFoundException: com.app.test.main$_channeltype

The portion com.app.test is my old package name. The new name is com.app.synergy but apparently the app still looks for the old name for classes. channeltype is a custom type I defined.

I tried Tools -> Clean Project. I even created a new project with new package name and tried copying all the modules (bas files) manually from B4A to B4A but surprisingly I am still getting the error. And I didn't use Designer at all. All UI is generated via code.

Please help.
 

Inman

Well-Known Member
Licensed User
Longtime User
Here
B4X:
java.lang.ClassNotFoundException: com.app.test.main$_channeltype


    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:251)
    at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2262)
    at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1638)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:658)
    at java.io.ObjectInputStream.readNewClass(ObjectInputStream.java:1514)
    at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:756)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1981)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1938)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readArray(RandomAccessFile.java:589)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readObject(RandomAccessFile.java:471)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readHelper(RandomAccessFile.java:403)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadObject(RandomAccessFile.java:364)
    at com.app.synergy.main._createpreferencescreen(main.java:752)
    at com.app.synergy.main._activity_create(main.java:402)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at com.app.synergy.main.afterFirstLayout(main.java:98)
    at com.app.synergy.main.access$100(main.java:16)
    at com.app.synergy.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5050)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:133)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com/app/test/main$_channeltype
    ... 31 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.app.test.main$_channeltype" on path: DexPathList[[zip file "/mnt/asec/com.app.synergy-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.app.synergy-1/lib, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    ... 31 more
java.lang.ClassNotFoundException: com.app.test.main$_channeltype
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Sorry Erel. I found the issue. When you mentione RAF, it suddenly struck me what might have happened.

When the app was com.test.app, I had created an RAF file containing my custom type called channeltype. Later this file is read using RAF for displaying in the data. After creating the RAF file (from the contents of a site), I realised the site doesn't get updated frequently and so I commented out the RAF file creation part and instead just read the file using RAF every time the app runs.

Now when I changed the packagename, I still used this old RAF file. I guess the file also contains the data type very explicitly, including the package name. Now I deleted that file, created it once again using RAF, commented out the RAF creation part and continued with just reading. And it works great.

I am extremely sorry for wasting your time, that too on a Sunday :(
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I just installed the new version 4.00.
When compiling and running with legacy debugger the program compile and runs just fine.
However, when I use the rapid debugger I receive:
An error occurred:
(Line: 18) Public Sub Initialize(pnl As Panel, Btns() As Button)
java.lang.ClassNotFoundException: anywheresoftware.b4a.pc.clsbutton

Obviously, this class does exist, but the Rapid debugger compiles it, but then can't see it when running.
This only occurs when using the Rapid debugger.
Any thoughts?
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I tried to export it as you suggested and the resultant zip file is over 4MB. (it's a very large application)
So I created a demo application that only creates and uses the class and it works fine in both legacy and rapid debugger.
I copied the exact dim/and execution code from the large application verbatim.
So it has to be an environmental issue with the large application. (something is in conflict with the class)...
Since I can't upload the 4MB, what do you suggest?
Thanks, Erel
Rusty
 
Upvote 0
Top