New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference #567
Comments
V/AutofillManager( 2994): requestHideFillUi(null): anchor = null still i have problem |
Please be more specific. I assume you upgraded to Flutter version 3.0.4 and are still experiencing the issue? Try to clear the cache files in your IDE, I use Android Studio and I would go to FIle > Invalidate Caches and follow the dialog. To be clear, I did not need to do anything besides "flutter upgrade" on my second development enviroment, that exhibited this error right before the upgrade, to fix this issue. I am not 100% confident this issue won't reoccur, if it does, I will be sure to come back and add to this discussion. |
@Sachinsowri can you please confirm the app has camera permissions on the device your testing your app on? |
yes permission granted in Mobile,
|
i am using VS code . will check with android studio . |
Bug's back on my end too. I uninstalled my app from the emulator and then reinstalled it, ran the qr_code_scanner and received this log: W/Gralloc4(25771): allocator 3.x is not supported Update: I then force-closed the app, opened the app, opened qr_code_scanner and it worked as expected no errors. Update 2: I then uninstalled and re-installed the app again, no bug occured. What could be causing this to occur only sometimes with the same environment conditions and code? |
any suggestion to solve this issue |
I've researched this bug and found the cause is an uninitialized Context var on the Android side, specifically within QrView.kt at line 117 we have the following code:
In my case, after running an Isolate to sync the app's database the value This error occurs anytime after you run an Isolate and then attempt to open the QR Code Scanner, it doesn't matter if you have permissions or not, this error comes before permissions are checked. Now, we just have to figure out why it's null, if we can't then we have to see how we can obtain a UI Context if this is null. I am trying to find where the QrShared.activity is set, this is where we can override a null and set a proper UI Context to fix this issue. |
okay thanks for your valuable time to spend this conversation . can you pls fix this issue as soon as possible. |
I have no experience fixing bugs in other people's libraries, I am going to see what I can do to get a valid Context here. In your case, are you running an Isolate before this error occurs, or please explain when the error occurs for you so. It might help me understand why the Context is null in the first place. |
For my case fix problem
|
i my app i have barcode scan option when open scan view . initialQRViewWidget called in inistate . no other function called. if permission not gives it worked after allow camera permission . if permission already allowed . i got that error all time |
initialQRViewWidget() { void onQRViewCreated(QRViewController controller) { scannedCode(Barcode scanCode) { Widget build(BuildContext context) { need to change any thing in my sample code |
Unfortunately that has no effect on this error, are you sure you posted in the correct post? |
@Sachinsowri I have found the fix, I have no experience in implementing said fix, but if someone would like to help me make my first contribution I would be thrilled to do such. I have commented on the commit itself that broke the plugin, @ the author, so I hope it gets fixed soon. I reviewed the latest commits and I found an anomoly in a refactoring done. I noticed logic was added to the I noticed that the plugin expects to bind to the engine once, so if any other plugins cause this plugin to detach, the plugin will not initialize correctly the second time. By removing the nulls the engine attachment is essentially immutable from detachments and it works as expected. The fix for now is to nullify rows 20 and 21 of FlutterQrPlugin.kt such as:
|
I created a fork for this issue, you can find it/use it in your pubspec.yaml by using the following code:
|
thanks it works |
You're welcome, my first public library fix! You should update this bug thread to include the Fork I made above. |
Thank you all for reporting and finding a fix. I have published version 1.0.1 which includes this fix. |
|
I Am using qr_code_scanner package in my app i am getting this error while show drwidget .
Flutter 3.0.2
qr_code_scanner : 1.0.0,
device : Android 11
sample code
initialQRViewWidget() {
if (mounted) {
setState(() {
isdelaycalled = true;
});
}
Future.delayed(const Duration(milliseconds: 500), () {
if (mounted) {
setState(() {
this.controller = null;
this.qrViewWidget = new QRView(
key: new GlobalKey(debugLabel: "QR11"),
onQRViewCreated: onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.greenAccent.shade700,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: Global.screenSize!.height * 0.35),
);
this.isdelaycalled = false;
});
}
});
}
void onQRViewCreated(QRViewController controller) {
if (mounted)
setState(() {
this.controller = controller;
this.controller!.scannedDataStream.first.then((scanData) {
scannedCode(scanData);
});
});
}
scannedCode(Barcode scanCode) {
this.getItem(scanCode);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new TitleText(
text: "Scan Code",
isBold: true,
textcolor: Colors.white,
),
backgroundColor: ServiceConstants.defaultColor),
body: new Column(
children: [
new Expanded(
child: this.isdelaycalled || this.isScanLoad
? Center(
child: new Container(
child: new Icon(
FontAwesomeIcons.cameraRetro,
size: 50,
color: Colors.blue,
),
),
)
: this.qrViewWidget!,
)
],
),
);
}
this error log
E/MethodChannel#flutter/platform_views(14830): Failed to handle method call
E/MethodChannel#flutter/platform_views(14830): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference
E/MethodChannel#flutter/platform_views(14830): at android.view.ViewConfiguration.get(ViewConfiguration.java:502)
E/MethodChannel#flutter/platform_views(14830): at android.view.View.(View.java:5394)
E/MethodChannel#flutter/platform_views(14830): at android.view.View.(View.java:5555)
E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:707)
E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:703)
E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:699)
E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:695)
E/MethodChannel#flutter/platform_views(14830): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228)
E/MethodChannel#flutter/platform_views(14830): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76)
E/MethodChannel#flutter/platform_views(14830): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12)
E/MethodChannel#flutter/platform_views(14830): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117)
E/MethodChannel#flutter/platform_views(14830): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#flutter/platform_views(14830): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#flutter/platform_views(14830): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter/platform_views(14830): at android.os.Looper.loop(Looper.java:262)
E/MethodChannel#flutter/platform_views(14830): at android.app.ActivityThread.main(ActivityThread.java:8248)
E/MethodChannel#flutter/platform_views(14830): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter/platform_views(14830): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
E/MethodChannel#flutter/platform_views(14830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:992)
E/FrameEvents(14830): updateAcquireFence: Did not find frame.
E/flutter (14830): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference
E/flutter (14830): at android.view.ViewConfiguration.get(ViewConfiguration.java:502)
E/flutter (14830): at android.view.View.(View.java:5394)
E/flutter (14830): at android.view.View.(View.java:5555)
E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:707)
E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:703)
E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:699)
E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:695)
E/flutter (14830): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228)
E/flutter (14830): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76)
E/flutter (14830): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12)
E/flutter (14830): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117)
E/flutter (14830): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70)
E/flutter (14830): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227)
E/flutter (14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/flutter (14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/flutter (14830): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (14830): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (14830): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/flutter (14830): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter (14830): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (14830): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (14830): at android.os.Looper.loop(Looper.java:262)
E/flutter (14830): at android.app.ActivityThread.main(ActivityThread.java:8248)
E/flutter (14830): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (14830): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
E/flutter (14830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:992)
E/flutter (14830): )
E/flutter (14830): #0 StandardMethodCodec.decodeEnvelope
E/flutter (14830): #1 MethodChannel._invokeMethod
E/flutter (14830):
E/flutter (14830): #2 TextureAndroidViewController._sendCreateMessage
E/flutter (14830):
E/flutter (14830): #3 AndroidViewController.create
E/flutter (14830):
E/flutter (14830): #4 TextureAndroidViewController.setSize
E/flutter (14830):
E/flutter (14830): #5 RenderAndroidView._sizePlatformView
E/flutter (14830):
E/flutter (14830):
The text was updated successfully, but these errors were encountered: