Skip to content
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] java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference #262

Closed
addtek opened this issue Jun 18, 2020 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@addtek
Copy link

addtek commented Jun 18, 2020

Hello there, i have tried playing video but video doesn't play and progress indicator keeps turning around.
Video can't play and throw the following error:

E/MethodChannel#flutter/platform_views( 6434): Failed to handle method call
E/MethodChannel#flutter/platform_views( 6434): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
E/MethodChannel#flutter/platform_views( 6434):  at android.view.ViewConfiguration.get(ViewConfiguration.java:476)
E/MethodChannel#flutter/platform_views( 6434):  at android.view.View.<init>(View.java:5198)
E/MethodChannel#flutter/platform_views( 6434):  at android.view.View.<init>(View.java:5393)
E/MethodChannel#flutter/platform_views( 6434):  at android.view.ViewGroup.<init>(ViewGroup.java:660)
E/MethodChannel#flutter/platform_views( 6434):  at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
E/MethodChannel#flutter/platform_views( 6434):  at android.webkit.WebView.<init>(WebView.java:659)
E/MethodChannel#flutter/platform_views( 6434):  at android.webkit.WebView.<init>(WebView.java:604)
E/MethodChannel#flutter/platform_views( 6434):  at android.webkit.WebView.<init>(WebView.java:587)
E/MethodChannel#flutter/platform_views( 6434):  at android.webkit.WebView.<init>(WebView.java:574)
E/MethodChannel#flutter/platform_views( 6434):  at android.webkit.WebView.<init>(WebView.java:564)
E/MethodChannel#flutter/platform_views( 6434):  at com.pichillilorenzo.flutter_inappwebview.InAppWebView.InputAwareWebView.<init>(InputAwareWebView.java:28)
E/MethodChannel#flutter/platform_views( 6434):  at com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebView.<init>(InAppWebView.java:612)   
E/MethodChannel#flutter/platform_views( 6434):  at com.pichillilorenzo.flutter_inappwebview.InAppWebView.FlutterWebView.<init>(FlutterWebView.java:68)E/MethodChannel#flutter/platform_views( 6434):  at com.pichillilorenzo.flutter_inappwebview.InAppWebView.FlutterWebViewFactory.create(FlutterWebViewFactory.java:28)
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:176)        
E/MethodChannel#flutter/platform_views( 6434):  at android.app.Dialog.dispatchOnCreate(Dialog.java:550)
E/MethodChannel#flutter/platform_views( 6434):  at android.app.Dialog.show(Dialog.java:391)
E/MethodChannel#flutter/platform_views( 6434):  at android.app.Presentation.show(Presentation.java:267)
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.plugin.platform.VirtualDisplayController.<init>(VirtualDisplayController.java:93)       
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:46)       
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:112)
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:95)
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226) 
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#flutter/platform_views( 6434):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#flutter/platform_views( 6434):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter/platform_views( 6434):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#flutter/platform_views( 6434):  at android.os.Looper.loop(Looper.java:181)
E/MethodChannel#flutter/platform_views( 6434):  at android.app.ActivityThread.main(ActivityThread.java:7045)
E/MethodChannel#flutter/platform_views( 6434):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter/platform_views( 6434):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#flutter/platform_views( 6434):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
E/flutter ( 6434): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference, null)
E/flutter ( 6434): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 6434): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter ( 6434): <asynchronous suspension>
E/flutter ( 6434): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter ( 6434): #3      AndroidViewController._create (package:flutter/src/services/platform_views.dart:633:54)
E/flutter ( 6434): #4      AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:550:14)
E/flutter ( 6434): #5      RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:175:29)
E/flutter ( 6434): #6      RenderAndroidView.performResize (package:flutter/src/rendering/platform_view.dart:156:5)
E/flutter ( 6434): #7      RenderObject.layout (package:flutter/src/rendering/object.dart:1746:9)
E/flutter ( 6434): #8      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #9      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #10     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #11     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #12     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #13     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #14     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:556:15)
E/flutter ( 6434): #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #16     RenderAspectRatio.performLayout (package:flutter/src/rendering/proxy_box.dart:526:13)
E/flutter ( 6434): #17     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #18     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #20     RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:266:13)
E/flutter ( 6434): #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #22     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #23     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #24     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #25     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1248:11)
E/flutter ( 6434): #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #27     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:11)
E/flutter ( 6434): #28     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:484:7)
E/flutter ( 6434): #29     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
E/flutter ( 6434): #30     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:399:14)
E/flutter ( 6434): #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #32     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #34     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #35     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1248:11)
E/flutter ( 6434): #36     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #37     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #38     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #39     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #40     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
E/flutter ( 6434): #41     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
E/flutter ( 6434): #4
W/System  ( 6434): A resource failed to call release. 
@addtek addtek added the bug Something isn't working label Jun 18, 2020
@pichillilorenzo
Copy link

I post here again my answer from my plugin (pichillilorenzo/flutter_inappwebview#390 (comment)):

I see that you don't call WidgetsFlutterBinding.ensureInitialized() before you are running your application.
As stated in the README.md file of my plugin, almost at the top of it (IMPORTANT Note for Android and iOS), you need to call it before runApp:

void main() {
 // it should be the first line in main method
 WidgetsFlutterBinding.ensureInitialized();

 // rest of your app code
 runApp(MyApp());
}

Now it should work.

Official wiki https://api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html

@sarbagyastha This should be added also to your documentation!

@jamesncl
Copy link

jamesncl commented Jun 20, 2020

I post here again my answer from my plugin (pichillilorenzo/flutter_inappwebview#390 (comment)):

I see that you don't call WidgetsFlutterBinding.ensureInitialized() before you are running your application.
As stated in the README.md file of my plugin, almost at the top of it (IMPORTANT Note for Android and iOS), you need to call it before runApp:

void main() {
 // it should be the first line in main method
 WidgetsFlutterBinding.ensureInitialized();

 // rest of your app code
 runApp(MyApp());
}

Now it should work.
Official wiki https://api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html

@sarbagyastha This should be added also to your documentation!

I believe this is not the problem. I also have this issue, and I'm definitely calling WidgetsFlutterBinding.ensureInitialized() before running the app. The problem is that this package conflicts fatally with packages which run Android's AlarmManager.

This is essentialy a duplicate of this issue on the flutter_inappwebview package. See there for a full reporoducible example of the error.

@jamesncl
Copy link

The author flutter_inappwebview package is working on a fix for this issue, it will be available in flutter_inappwebview version 3.4.0. When that comes out, if @sarbagyastha updates youtube_player_flutter to use that version of inappwebview, the problem will be resolved

@sarbagyastha
Copy link
Owner

@sarbagyastha This should be added also to your documentation!

@pichillilorenzo Thank you, will add it.

The author flutter_inappwebview package is working on a fix for this issue, it will be available in flutter_inappwebview version 3.4.0. When that comes out, if @sarbagyastha updates youtube_player_flutter to use that version of inappwebview, the problem will be resolved

Waiting for the update.

@pichillilorenzo
Copy link

@sarbagyastha Published new 3.4.0 version!

@sarbagyastha
Copy link
Owner

sarbagyastha commented Jun 22, 2020

@sarbagyastha Published new 3.4.0 version!

@pichillilorenzo Thanks 🎉

@sarbagyastha
Copy link
Owner

Updated flutter_inappwebview version constraint to >=3.4.0<3.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants