Android Snackbar NullPointerException in Fragment -
i want add basic snackbar application have received error couldn't figure out why.
i added code in oncreateview() method in fragment.
snackbar.make(view, "snackbar", snackbar.length_long) .setaction("action", null).show();
and received error:
06-01 10:26:09.955 1232-1232/? e/activitythread﹕ failed find provider info me.muraterdogan.watchme.metricacontentprovider 06-01 10:26:10.075 1232-1447/? e/activitythread﹕ failed find provider info me.muraterdogan.watchme.yplcontentprovider 06-01 10:33:55.044 6646-6646/? e/androidruntime﹕ fatal exception: main process: me.muraterdogan.watchme, pid: 6646 java.lang.nullpointerexception: attempt invoke virtual method 'android.content.context android.view.viewgroup.getcontext()' on null object reference @ android.support.design.widget.snackbar.<init>(snackbar.java:116) @ android.support.design.widget.snackbar.make(snackbar.java:140) @ me.muraterdogan.watchme.fragments.trendingfragment.getdata(trendingfragment.java:90) @ me.muraterdogan.watchme.fragments.trendingfragment.oncreateview(trendingfragment.java:83) ...
if fragment added existing activity(remember can add through xml), should call snackbar's method onactivitycreated() method of fragment.
@override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); snackbar.make(view, "snackbar", snackbar.length_long) .setaction("action", null).show(); }
Comments
Post a Comment