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


Solutions on the web

Solution icon of stackoverflow
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of github
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
via Stack Overflow by Nemanja Mitrovcan
, 1 year ago
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of github
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
via Stack Overflow by Unknown author, 1 year ago
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
via Stack Overflow by Unknown author, 1 year ago
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Solution icon of stackoverflow
via Stack Overflow by Amir
, 1 year ago
Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Stack trace

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
	at android.widget.Toast.<init>(Toast.java:102)
	at android.widget.Toast.makeText(Toast.java:259)
	at com.example.nkwpy.myapplication.MainFragment.query(MainFragment.java:176)
	at com.example.nkwpy.myapplication.MainFragment.access$000(MainFragment.java:46)
	at com.example.nkwpy.myapplication.MainFragment$queryListener.onClick(MainFragment.java:161)
	at android.view.View.performClick(View.java:5207)
	at android.view.View$PerformClick.run(View.java:21177)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:148)
	at android.app.ActivityThread.main(ActivityThread.java:5458)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

Write tip

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

Users with the same issue

Samebug visitor profile picture
Unknown user
Once, 1 year ago
Samebug visitor profile picture
Unknown user
Once, 1 year ago
4 times, 1 year ago
Once, 1 year ago
13 times, 3 months ago
11 more bugmates