[英]Android app returns "Error: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)"
[英]Flutter:PlatformException(error, Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)'
我正在嘗試使用此插件以管理員身份啟用我的應用程序。
這是我下面的代碼:
@override
void initState() {
super.initState();
Admin.enable();
_callStreamSubscription = phoneStateCallEvent.listen((PhoneStateCallEvent event) {
print('Call is Incoming or Connected: ' + event.stateC);
if(event.stateC=="true"){
_invokeNativeMethod("startRecording");
}
else if(event.stateC=="false"){
_invokeNativeMethod("stopRecording");
}
});
}
錯誤如下:
E/flutter ( 8036): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)' on a null object reference, null)
E/flutter ( 8036): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 8036): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter ( 8036): <asynchronous suspension>
E/flutter ( 8036): #2 Admin.enable (package:admin/admin.dart:10:21)
E/flutter ( 8036): #3 _MyHomePageState.initState (package:automatic_call_recorder/main.dart:55:11)
任何幫助將不勝感激!
所以,我得到了解決方案:
實際上,我嘗試在舊的 package 中添加代碼,其中我刪除了這一行的平台特定代碼
GeneratedPluginRegistrant.registerWith(flutterEngine);
因此發生了錯誤。 所以我再次添加了該行,現在它工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.