Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

In Flutter implementing native SDK witihin Kotlin Using the Context.getSystemService(Context.NOTIFICATION_SERVICE) leads to a nullpointer exception

I have a big problem and does not know the answer, maybe someone can help me:

I want to include a third party sdk into flutter which means I created a channel and am currently implementing the native in kotlin code.

To get started with the third party sdk I implemented a class which extends FlutterApplication and implements a NATIVECALLBACK, Within this class I got an onCreate() method, which is not called when building my app (I assume cause flutter handles it differently) so I created in my mainactivity an object from this class an am calling the method from there. In This method I need a notification to initialise my third party sdk.

I got my own class within kotlin in which I want to work with the android.content.Context and here is where the problem starts:

When using my following method, I got a nullpointerexception and I assume that its because I use flutter and the context must be handled differently but I am not sure about that.

var notificationManager =
getSystemService(
android_content.Context.NOTIFICATION_SERVICE) as NotificationManager

The error message ios the following:

Failed to handle method call java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference

Does anyone know what I can do? I hope you can get the problem

question from:https://stackoverflow.com/questions/65914710/in-flutter-implementing-native-sdk-witihin-kotlin-using-the-context-getsystemser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...