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

Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference #2924

Closed
vitorqshr opened this issue Jun 24, 2019 · 54 comments

Comments

@vitorqshr
Copy link

Bug

App breaking when entering the screen

Environment info

Samsuns Galaxy S8
react-native : 0.59.8
react-native-maps : 0.24.0 to 0.24.2 (tried both)

React native info output:

image

Reproducible sample code

...

this.state = {
region: {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}
}

.....

<MapView
ref={map => this.mapView = map}
initialRegion={this.state.region}
region={this.state.region}
rotateEnabled={false}
scrollEnabled={false}
zoomEnabled={false}
showsPointsOfInterest={false}
showsBuildings={false}
showsUserLocation={true}
loadingEnabled={true}
/>

@rborn
Copy link
Collaborator

rborn commented Jun 25, 2019

@vitorqshr can you please run a test with the master version? we just merged #2924 (cc: @mikehardy )

@mikehardy
Copy link
Contributor

If you are using react-native less than 0.60 my patch isn’t necessary I don’t think.

If (big IF! not sure this problem is AndroidX-related) this is an AndroidX problem with react-native 0.59.x or lower, you would see it if your app was androidX already, and you had not run npm i jetifier and npm jetify (along with hooking it in package.json postinstall)

If this wasn’t an AndroidX app then I’m not sure it would show up?

I suppose issue templates in modules need to be updated to include a question if the app is AndroidX or not

@rborn
Copy link
Collaborator

rborn commented Jul 11, 2019

@christopherdro just published 0.25.0 on npm, would be great to give it a shot and report back

@marchrenno
Copy link

I found a solution. Not sure if it's a long term one, but this will let you guys work until a permanent solution is found.
Just clear your cash: npm start -- --reset-cache
And restart the project.
It worked for me.
FYI, I didn't eject my project yet.

@rborn rborn closed this as completed Aug 22, 2019
@Jega1
Copy link

Jega1 commented Sep 18, 2019

I have the same propblem. i tried to all these methods not worked for me help!!!!!

@Mitra98t
Copy link

@Jega1 (sorry for my English) just try to type in the terminal react-native run-android instead of react-native start... that worked for me

@fatihmert
Copy link

I guess solved this error. So I'm using react-native version 0.61

My impression are;

I tested it on more than one real device. I loop without using components like flatlist or recyclerlist. (I think react keeps these components in the cache and provides performance for the next refresh.) I get this error when I fetch and loop data multiple times. It doesn't happen the first time because RAM is fresh. When I started testing on different devices with high hardware capabilities, I realized that I had to fetch more data to get this error.

I have almost 4GB ram in the emulator (HAXM) I've fetched the data for 5 minutes yet I haven't encountered this error. The tests I made using flatlist without going to 3rd party were very successful.

You can try switching to any flatlist or 3rd party listing method. First, do not forget to convert your data to the component.

I must remind you; Even if a react-native bridge is performing, we should make sure that our code has permons.

Enjoy coding.

@Jega1
Copy link

Jega1 commented Oct 11, 2019

@Mitra98t @fatihmert thanks a lot.

@anAnun
Copy link

anAnun commented Nov 9, 2019

I just had the same EXACT problem and errors. Clear the data and cache on your expo app on your phone, then it should work

@nolife08021
Copy link

clear app cache from the physical device works for me.

@mayu-496
Copy link

I was getting the same problem with expo .. stopped running the app , cleared expo recently open project and again started with ' expo start ' ... This worked for me..

@gowthamrn4
Copy link

gowthamrn4 commented Dec 18, 2019

Just kill all node process and start npm server and run application
killall -9 node

@bsor-dev
Copy link

For expo, this happened to me when I clear data and cache of my Expo. Just restart your expo run 'epxo start -c'

@dancherb
Copy link

What about when your tracking detects this happening in production?

@Satyam-code143
Copy link

@nolife08021
Same here ..
I have just cleared the cache(app) from my device.
Thank You!1

@kalleriakronos24
Copy link

What about when your tracking detects this happening in production?

i kinda still looking for this, just incase

@PedroBern
Copy link

The same error here, fix after clear cache on the phone

@vicaster
Copy link

vicaster commented Sep 17, 2020

I have the same persistent problem.
When I have a lot of TextInput, the application generates this error..
So I isolated these TextInputs in a different screen. And this error comes back again but with a lower frequency.
Has anyone found a solution?
thx a lot for an futur answer.

It is possible to clean the cache from the app?

@Shahzaib1999
Copy link

@vicaster have you found any solution?

@vicaster
Copy link

vicaster commented Sep 28, 2020

@Shahzaib1999 nop 😭
If i found a soluce i will post it on this forum. ;)

vicaster referenced this issue in facebook/react-native Oct 2, 2020
Summary:
This fixes TextInput measurement caching. Previously we were not setting the correct Spannable in the cache; we needed to additional Spans to it to indicate font size and other attributes.

This brings Fabric closer to how non-Fabric was measuring Spannables for TextInputs (see ReactTextInputShadowNode.java).

This should fix a few crashes and will be most noticeable with dynamically-sized multiline textinputs where the number of lines changes over time.

This also allows us to transmit less data from C++ to Java in the majority of cases.

Changelog: [Internal]

Differential Revision: D23670779

fbshipit-source-id: cf9b8c848b9e0c2619e01766b72b074248466825
@alissonarom
Copy link

I just had the same EXACT problem and errors. Clear the data and cache on your expo app on your phone, then it should work

Funcionou para mim. Obrigado

@eldano1995
Copy link

Same problem here. No solution yet??

@vicaster
Copy link

vicaster commented Oct 18, 2020

@eldano1995 nop. May be the 0.64 version will resolve it. i saw a commit which talk about resolve textInput bug.
this commit :

facebook/react-native@6524e61

@jafar-jabr
Copy link

why this bug is closed ?!!!

@nahidmbstu
Copy link

this is an active bug

@HoppeDevz
Copy link

Clear the cache from expo project.
-> expo r -c
and clear the cache from your celphone

@ketan1062
Copy link

facebook/react-native#17530

@tiggem1993
Copy link

Hi I have recently face same crash with my production build. I have check my Firebase Crashlytics and found it occurred after user input some text and press the submit button.

DEVICE INFO
Android: 10
Device: samsung Galaxy Tab A (8.0", 2019)
RAM free: 368.54 MB
Disk free: 12.67 GB

Dependencies
"react": "16.13.1",
"react-native": "0.63.4",
"@react-native-firebase/crashlytics": "^10.1.0",

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference
       at android.graphics.drawable.DrawableContainer$DrawableContainerState.createAllFutures(DrawableContainer.java:880)
       at android.graphics.drawable.DrawableContainer$DrawableContainerState.getOpacity(DrawableContainer.java:1163)
       at android.graphics.drawable.DrawableContainer.getOpacity(DrawableContainer.java:434)
       at android.graphics.drawable.InsetDrawable.getOpacity(InsetDrawable.java:259)
       at android.view.View.computeOpaqueFlags(View.java:19427)
       at android.view.View.setBackgroundDrawable(View.java:24704)
       at androidx.appcompat.widget.AppCompatEditText.setBackgroundDrawable(AppCompatEditText.java:112)
       at android.view.View.setBackground(View.java:24597)
       at android.view.View.<init>(View.java:6198)
       at android.widget.TextView.<init>(TextView.java:1215)
       at android.widget.EditText.<init>(EditText.java:106)
       at android.widget.EditText.<init>(EditText.java:102)
       at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:74)
       at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:69)
       at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:65)
       at com.facebook.react.views.textinput.ReactEditText.<init>(ReactEditText.java:111)
       at com.facebook.react.views.textinput.ReactTextInputManager.createViewInstance(ReactTextInputManager.java:128)
       at com.facebook.react.views.textinput.ReactTextInputManager.createViewInstance(ReactTextInputManager.java:84)
       at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:139)
       at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:83)
       at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:261)
       at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:186)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.dispatchPendingNonBatchedOperations(UIViewOperationQueue.java:1112)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1083)
       at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
       at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
       at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:997)
       at android.view.Choreographer.doCallbacks(Choreographer.java:797)
       at android.view.Choreographer.doFrame(Choreographer.java:728)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8107)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

@snehalm-iprogrammer
Copy link

Hi I have recently face same crash with my production build. I have check my Firebase Crashlytics and found it occurred after user input some text and press the submit button.

DEVICE INFO
Android: 10
Device: samsung Galaxy Tab A (8.0", 2019)
RAM free: 368.54 MB
Disk free: 12.67 GB

Dependencies
"react": "16.13.1",
"react-native": "0.63.4",
"@react-native-firebase/crashlytics": "^10.1.0",

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference
       at android.graphics.drawable.DrawableContainer$DrawableContainerState.createAllFutures(DrawableContainer.java:880)
       at android.graphics.drawable.DrawableContainer$DrawableContainerState.getOpacity(DrawableContainer.java:1163)
       at android.graphics.drawable.DrawableContainer.getOpacity(DrawableContainer.java:434)
       at android.graphics.drawable.InsetDrawable.getOpacity(InsetDrawable.java:259)
       at android.view.View.computeOpaqueFlags(View.java:19427)
       at android.view.View.setBackgroundDrawable(View.java:24704)
       at androidx.appcompat.widget.AppCompatEditText.setBackgroundDrawable(AppCompatEditText.java:112)
       at android.view.View.setBackground(View.java:24597)
       at android.view.View.<init>(View.java:6198)
       at android.widget.TextView.<init>(TextView.java:1215)
       at android.widget.EditText.<init>(EditText.java:106)
       at android.widget.EditText.<init>(EditText.java:102)
       at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:74)
       at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:69)
       at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:65)
       at com.facebook.react.views.textinput.ReactEditText.<init>(ReactEditText.java:111)
       at com.facebook.react.views.textinput.ReactTextInputManager.createViewInstance(ReactTextInputManager.java:128)
       at com.facebook.react.views.textinput.ReactTextInputManager.createViewInstance(ReactTextInputManager.java:84)
       at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:139)
       at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:83)
       at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:261)
       at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:186)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.dispatchPendingNonBatchedOperations(UIViewOperationQueue.java:1112)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1083)
       at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
       at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
       at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:997)
       at android.view.Choreographer.doCallbacks(Choreographer.java:797)
       at android.view.Choreographer.doFrame(Choreographer.java:728)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8107)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

facing the same issue .. can anyone help?

@DanielFredriksson
Copy link

Any fix?

@vicaster
Copy link

To resolve this problem i was created my own , it's a custom keyboard.
So it's not THE solution but when my screen have a lot of there is no crash.

Waiting for react native's staff resolve this problem.....
Have fun.

@chrisregner
Copy link

chrisregner commented Oct 27, 2021

Got this issue on production this week (tracked via Sentry). I think we should reopen this issue

My bad. It seems that the fix is on its way to release: facebook/react-native@254493e

NullPointerException
Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference

@mikehardy
Copy link
Contributor

That one is actually more of a workaround than a fix, you may apply it at any time, I see it in the upgrade-helper diffs for upgrades to react-native 0.67-rc series, and you can take it from there - it's only referencing things that you apply directly not any internal react-native code:

https://react-native-community.github.io/upgrade-helper/?from=0.66.1&to=0.67.0-rc.2

@vladi965
Copy link

@vitorqshr , ¿puede ejecutar una prueba con la versión maestra? acabamos de fusionar # 2924 (cc: @mikehardy )

Debes borrar el cache de tu celular a mi me funciono :)

@kkureli
Copy link

kkureli commented Dec 16, 2021

any solution ?

@mikehardy
Copy link
Contributor

That one is actually more of a workaround than a fix, you may apply it at any time, I see it in the upgrade-helper diffs for upgrades to react-native 0.67-rc series, and you can take it from there - it's only referencing things that you apply directly not any internal react-native code:

https://react-native-community.github.io/upgrade-helper/?from=0.66.1&to=0.67.0-rc.2

@kkureli

@ravikumar-yadav
Copy link

@eldano1995 nop. May be the 0.64 version will resolve it. i saw a commit which talk about resolve textInput bug. this commit :

facebook/react-native@6524e61

same issue on oneplus with 0.64.1

@szyymoon
Copy link

Any updates?
same issue on "react-native": "0.64.2" which cooperate with "react-native-paper": "^4.9.2",

@AllanBengco
Copy link

Adding my bug report to this thread.

Using React Native 0.64.2, with Expo, running the app in development is fine. The build for Google Play is another matter.

@szyymoon
Copy link

What's more this bug is so rare that I cant do more debug.. Its occurs also in production.

@davmaene
Copy link

I had the same problem; but i solved it by deleting data from my client expo app

@gurkanucar
Copy link

Same problem on expo. It doesn't matter for me while developing but if it will cause a problem in production this is a problem :/

@brainydee
Copy link

wipe your virtual device data reset cache and restart simulator

@kristopalka
Copy link

kristopalka commented Sep 11, 2022

The same issue, occurs when using TextInput. RN version 0.69.5

@avishain
Copy link

Issue still exists in RN 0.70.0.
It worked fine with version 0.65.1.
Anyone to the rescue? I can share my dependencies list if it helps somehow.

@lieberscott
Copy link

lieberscott commented Nov 2, 2022

Still getting this error. Happens when using TextInput. Any workaround yet?

@sourabhCCSD
Copy link

The REMEDY ..for android

Log out of the app.
From a Phone Home screen, navigate: Apps icon > Settings > Apps (Phone section)
Tap Application Manage.
From the Dropdown menu ensure All apps is selected, then locate and tap Expo Pass app.
Tap Storge.
Tap CLEAR CACHE.

@vishuk570
Copy link

Add the flowing line of code into /android/app/src/main/res/values/styles.xml.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:editTextBackground">@android:color/transparent</item> <-- Add this ... </style>
Hope this will work.

@HobaiGuigui
Copy link

HobaiGuigui commented Feb 6, 2023

Just Clean the cache witch this folownig command:

yarn start -c OR npx expo start -c

@Onyelaudochukwuka
Copy link

The REMEDY ..for android

Log out of the app. From a Phone Home screen, navigate: Apps icon > Settings > Apps (Phone section) Tap Application Manage. From the Dropdown menu ensure All apps is selected, then locate and tap Expo Pass app. Tap Storge. Tap CLEAR CACHE.

This worked for me Thanks!!

@vaish8529
Copy link

vaish8529 commented Jun 1, 2023

Add the flowing line of code into /android/app/src/main/res/values/styles.xml. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:editTextBackground">@android:color/transparent</item> <-- Add this ... </style> Hope this will work.
TEXTINPUT

Thanks for solution but I am facing issue after applying above code,textinputs ignoring css.

And Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference facing issue on live app(Crashes and ANRs).

@godiegogt
Copy link

The problem is that those fixes just work for developing mode, doesn't work for production apps.

@dgreasi
Copy link

dgreasi commented Jan 12, 2024

Same issue with the following env:

"react-native": "0.72.5",
"react-native-maps": "^1.8.0",

@phaniankur
Copy link

When it works, it works. Resetting worked fine for me. 👍
npm start -- --reset-cache

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

No branches or pull requests