Android Question string.replace() changing special character in string

Kiran Raotole

Active Member
Licensed User
i have a string : msg = "%this is test message%"
I am changing special character "%" = "%25"

B4X:
msg.Replace("%","%25")

Its showing error ::
B4X:
Error occurred on line: 49 (Main)
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.shell.Shell$RemoteObject
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:767)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6605)
    at android.view.View.performClickInternal(View.java:6582)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25897)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
java.lang.OutOfMemoryError: Failed to allocate a 554369040 byte allocation with 12582912 free bytes and 190MB until OOM, max allowed footprint 14424568, growth limit 201326592
    at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
    at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
    at anywheresoftware.b4a.shell.Shell.fillHtSubs(Shell.java:595)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:369)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6605)
    at android.view.View.performClickInternal(View.java:6582)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25897)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
java.lang.OutOfMemoryError: Failed to allocate a 571146256 byte allocation with 12582912 free bytes and 190MB until OOM, max allowed footprint 14423528, growth limit 201326592
    at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
    at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
    at anywheresoftware.b4a.shell.Shell.fillHtSubs(Shell.java:595)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:369)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6605)
    at android.view.View.performClickInternal(View.java:6582)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25897)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 

DonManfred

Expert
Licensed User
Longtime User
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.shell.Shell$RemoteObject
You need to provide more code.

Where does msg come from? where are you adding the result to?

best is to upload a small project
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Helping a friend who gets the same error msg...

If you DON'T assign the result of Replace to a variable, you get an error msg ONLY if there are special chars involved.

[obviously, it is always needed to assign the value to a variable using Replace]
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…