question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android crash: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

See original GitHub issue

It 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:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nikolaikcommented, Nov 20, 2017

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 calling Toast.makeText?

0reactions
skrepeckicommented, May 4, 2021

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); }

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found