I'm trying to call method share() from a fragment. share() is in MainActivity.java
Button shareButton = new Button(getActivity());
shareButton.setOnClickListener(new View.onClickListener() {
@Override
public void onClick(View v) {
MainActivity ma = new MainActivity();
ma.share(v); //Doesn't work! NullPointerException
}
}
share():
public void share(View v) {
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, shareString);
startActivity(Intent.createChooser(i, "#CrystalMaths"));
}
