title: Attempt to invoke a interface method on a null object reference
body: <p>I am a beginner in android and I tried experimenting with interface methods, but I am stuck at this problem,</p>
  <pre><code>public class FragmentA extends Fragment {
      private Button changeButton;
      private TextView changeText;
      private OnClickBt onclickbt;
  
      interface OnClickBt {
          void OnClickButton(View view);
          void OnLongClickButton(View view);
      }
  
      public void setOnClickBtListner(OnClickBt obj) {
          onclickbt = obj;
      }
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment, container, false);
      }
  
  
      @Override
      public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          changeButton = view.findViewById(R.id.changeButton);
          changeText = view.findViewById(R.id.tv_text);
          changeButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  onclickbt.OnClickButton(view);
              }
          });
      }
  }
  </code></pre>
  <p>And the code in my MainActivity.java is</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
      private FragmentA ifc = new FragmentA();
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Fragment fragment = new FragmentA();
          getSupportFragmentManager().beginTransaction().replace(R.id.container,fragment).commit();
          ifc.setOnClickBtListner(new FragmentA.OnClickBt() {
              @Override
              public void OnClickButton(View view) {
                  Toast.makeText(MainActivity.this, &quot;Button Clicked&quot;, Toast.LENGTH_SHORT).show();
              }
  
              @Override
              public void OnLongClickButton(View view) {
                  Toast.makeText(MainActivity.this,&quot;Button Long clicked&quot;,Toast.LENGTH_SHORT).show();
              }
          });
      }
  }
  </code></pre>
  <p>Here, it's throwing a exception of attempt to invoke interface method using null reference. I tried to intialize OnClickBt on onAttach(), but it threw an exception saying context cannot be casted
  this way.</p>
  <p>Can anyone where I made mistake and how to resolve this,</p>