Android crash: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
See original GitHub issueIt looks like the library tries to show an error. Here’s the backtrace:
Toast.java:138android.widget.Toast.<init>
Toast.java:385android.widget.Toast.makeText
AddCardDialogFragment.java:210com.gettipsi.stripe.dialog.AddCardDialogFragment$4.onError
Stripe.java:341com.stripe.android.Stripe.tokenTaskPostExecution
Stripe.java:32com.stripe.android.Stripe.access$100
Stripe.java:60com.stripe.android.Stripe$1$1.onPostExecute
Stripe.java:43com.stripe.android.Stripe$1$1.onPostExecute
AsyncTask.java:660android.os.AsyncTask.finish
AsyncTask.java:-1android.os.AsyncTask.-wrap1
AsyncTask.java:677android.os.AsyncTask$InternalHandler.handleMessage
Handler.java:102android.os.Handler.dispatchMessage
Looper.java:154android.os.Looper.loop
ActivityThread.java:6776android.app.ActivityThread.main
Method.java:-2java.lang.reflect.Method.invoke
ZygoteInit.java:1520com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
ZygoteInit.java:1410com.android.internal.os.ZygoteInit.main
Here’s the line in question: https://github.com/spin-org/tipsi-stripe/blob/master/android/src/main/java/com/gettipsi/stripe/dialog/AddCardDialogFragment.java#L210
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Attempt to invoke virtual method 'android.content.Context ...
The method getActivity will always return null. Also as far as possible don't try to keep your Activity reference in your Fragment ......
Read more >Context | Android Developers
Stay organized with collections Save and categorize content based on your ... to retrieve a LayoutInflater for inflating layout resources in this context....
Read more >Crash in java.lang.NullPointerException: Attempt to invoke ...
CharSequence android.content.res.StringBlock.get(int)'' on a null object reference at android.content.res.AssetManager.getResourceValue(AssetManager.java).
Read more >Java.Lang.NullPointerException when show Popup.
... 'Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference'.
Read more >After Incremental Build getActivity() is a null object [37090327]
NullPointerException : Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just saw the same error in our app in prod, pointing to line 210 in AddCardDialogFragment.java.
The exception happened right after the user canceled the dialog. Should we just check if
getActivity() != null
before callingToast.makeText
?private fun bitmapDescriptorFromVector(context: Activity, vectorResId: Int):BitmapDescriptor { var vectorDrawable = ContextCompat.getDrawable(context, vectorResId); vectorDrawable!!.setBounds( 0, 0, vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight() ); var bitmap = Bitmap.createBitmap( vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888 ); var canvas = Canvas(bitmap); vectorDrawable.draw(canvas); return BitmapDescriptorFactory.fromBitmap(bitmap); }