Java Question NoSuchMethodError: no Direct Method

barx

Well-Known Member
Licensed User
Longtime User
Pulling my hair out here:

Updating NotificationBuilder Lib.

Existing lib code was like this

B4X:
        setObject(new NotificationCompat.Builder(ba.context));
When I run this version on Oreo (26) I get the error of not having a channel ID

Latest version of support lib deprecates NotificationCompat.Builder(Context) and now uses NotificationCompat.Builder(Context, String) to allow you to pass a channel ID as a string.

So, following the docs I simply change my code to

B4X:
private static String CHANNEL_ID = "Default";
...
...
...
setObject(new NotificationCompat.Builder(ba.context, CHANNEL_ID));

When I run this in b4a I get the following error

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
no extras
main_togglenotification_checkedchange (java line: 697)
java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/barxdroid.nbtest-tkciqX_yZSsiVugDO3uc8Q==/base.apk)
at uk.co.barxdroid.notificationbuilder.NotificationBuilder.Initialize(NotificationBuilder.java:91)

at barxdroid.nbtest.main._togglenotification_checkedchange(main.java:697)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.objects.CompoundButtonWrapper$1.onCheckedChanged(CompoundButtonWrapper.java:44)
at android.widget.CompoundButton.setChecked(CompoundButton.java:171)
at android.widget.ToggleButton.setChecked(ToggleButton.java:71)
at android.widget.CompoundButton.toggle(CompoundButton.java:127)
at android.widget.CompoundButton.performClick(CompoundButton.java:132)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
main_togglenotification_checkedchange (java line: 697)
java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/barxdroid.nbtest-tkciqX_yZSsiVugDO3uc8Q==/base.apk)
at uk.co.barxdroid.notificationbuilder.NotificationBuilder.Initialize(NotificationBuilder.java:91)
at barxdroid.nbtest.main._togglenotification_checkedchange(main.java:697)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.objects.CompoundButtonWrapper$1.onCheckedChanged(CompoundButtonWrapper.java:44)
at android.widget.CompoundButton.setChecked(CompoundButton.java:171)
at android.widget.ToggleButton.setChecked(ToggleButton.java:71)
at android.widget.CompoundButton.toggle(CompoundButton.java:127)
at android.widget.CompoundButton.performClick(CompoundButton.java:132)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

NotificationBuilder.java: Line 91 is the changed line.

Been at it a while now, cannot figure it out.

Using:

b4a - 7.80
support repo - 47

Any Ideas?
 

DonManfred

Expert
Licensed User
Longtime User
The Builder itself does not have a second parameter.
Create the builder and set the Channel with the responsive method.

Something like
B4X:
setObject(new NotificationCompat.Builder(ba.context));
getObject().setChannel(my_channel);

You can make this configureable by the developer. Use the one the Developer prefer. :)
 

barx

Well-Known Member
Licensed User
Longtime User

barx

Well-Known Member
Licensed User
Longtime User
It's strange. I would also guess the useof out of date dependancies but as far as I can tell all is newest.

Android Studio Project is set to

compileSdkVersion 27
buildToolsVersion '27.0.1'

defaultConfig {
minSdkVersion 16
targetSdkVersion 27
compile 'com.android.support:support-v4:27.0.2'

Library code states

@DependsOn(values = {"com.android.support:support-v4", "NotificationBuilder.aar"})
Does a version need stating here, only ever seen it done like this.
 

DonManfred

Expert
Licensed User
Longtime User

barx

Well-Known Member
Licensed User
Longtime User
i would guess you are not using the new B4A SDK Manager.
Google has stopped updating the maven repositories a year ago.

For B4A <7.8: https://www.b4x.com/android/forum/threads/gui-sdk-manager-for-newer-versions-of-android-tools.80090/
For B4A 7.8+ you find a link to the correct thread in the link above. The SDK Manager is now part of the Installation.

Use the SDSK Manager to install the SDK and all recomended items. Make sure to setup the IDE to use this SDK. Tools configure Paths.

I am using b4a 7.8, installed today. Using built in manager.

path set to 'D:\Current\Android\sdk\platforms\android-27\android.jar'

Check additional and b4a libs folders for old support lib files.

Project cleaned scrubbed and polished both in AS and b4a. Maybe I will uninstall everything and try again.
 

barx

Well-Known Member
Licensed User
Longtime User
No idea what I have done but it appears to be working.......

for now.
 
Top