I am creating common java class for ProgressBar
i getting error like below
java.lang.NullPointerException: Attempt to invoke virtual method 'void app.bridgecenterandstaffmanagament.com.bridgecenterandstaffmanagament.CommonClass.Singletonclass_obj.showProgressBar(android.content.Context)' on a null object reference
at 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 the layout for this 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 my last Project..please help me any one.