Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Attempt to invoke virtual method 'android.content.res.Resources android.app.Activity.getResources()' on a null object reference #45

Open
RasyidMF opened this issue May 26, 2021 · 1 comment

Comments

@RasyidMF
Copy link

When i was installing Background Service or some other service, i got this error. But somehow i fix it with my own technique...
This some error information.

W/System.err(20027): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.app.Activity.getResources()' on a null object reference
W/System.err(20027): 	at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.getPage(FlutterPluginPdfViewerPlugin.java:157)
W/System.err(20027): 	at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.access$100(FlutterPluginPdfViewerPlugin.java:29)
W/System.err(20027): 	at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin$1.run(FlutterPluginPdfViewerPlugin.java:70)

When i take a look at FlutterPluginPdfViewerPlugin.java, error appear at line 157 and 158

double width = instance.activity().getResources().getDisplayMetrics().densityDpi * page.getWidth();
double height = instance.activity().getResources().getDisplayMetrics().densityDpi * page.getHeight();

I think there is some problem with activity, so i decided manually replaced it into

double width = instance.context().getResources().getDisplayMetrics().densityDpi * page.getWidth();
double height = instance.context().getResources().getDisplayMetrics().densityDpi * page.getHeight();

And it works without any error.

I don't make this as "SOLUTION" for while, i just want make sure this is safe to do.

@enveraltin
Copy link

This is fixed in #49, feel free to use my branch as a dependency if you like.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants