android - How to pass getContext to Java class not working? -


this question has answer here:

i creating common java class progressbar getting error below

java.lang.nullpointerexception: attempt invoke virtual method 'void app.bridgecenterandstaffmanagament.com.bridgecenterandstaffmanagament.commonclass.singletonclass_obj.showprogressbar(android.content.context)' on null object reference                                                                                                                            @ app.bridgecenterandstaffmanagament.com.bridgecenterandstaffmanagament.fragments.notificationfragment.oncreateview(notificationfragment.java:41) 

fragment

public class notificationfragment extends fragment {       public notificationfragment() {         // required empty public constructor     }      recyclerview recyclerview;        @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate layout fragment          view v = inflater.inflate(r.layout.fragment_notification, container, false);           recyclerview = v.findviewbyid(r.id.recylierview_notification);           // singletonclass_obj.getinstance().showprogressbar(getactivity());         singletonclass_obj.getinstance().showprogressbar(getcontext());        // print();          return v;     }   } 

java class

public class singletonclass_obj extends application{     private  progressbar progressbar;     private static singletonclass_obj singletonclassobj;        public static singletonclass_obj getinstance() {         return singletonclassobj;     }      @override     public void oncreate() {         super.oncreate();         singletonclassobj = this;     }      public void showprogressbar(context context)     {       //  toast.maketext(context, "welcometoindia", toast.length_short).show();         progressbar = new progressbar(context, null, android.r.attr.progressbarstylesmall);     }      public void hideprogressbar()     {         if (progressbar !=null && progressbar.isshown())             progressbar.setvisibility(view.invisible);      }  } 

same codeing working fine last project..please me one.

as per above comment in question

try add singletonclass_obj in manifest file inside application tag below code

<application         android:name=".singletonclass_obj"<!--add here singletonclass_obj class -->         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:roundicon="@mipmap/ic_launcher_round"         android:supportsrtl="true"         android:theme="@style/apptheme"> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -