I have been struggling in this for 2days, can anybody give a suggestion on how to solve it?
This is my WhatsApp2 activity...
public class WhatsApp2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void whatsappSend(){
try {
String toNumber = "xxxxxxxxxx";
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + "" + toNumber+ "?body=" + ""));
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
catch (Exception e){
e.printStackTrace();
}
}
}
And I am trying to call the whatsappSend()
from another activity like this...
public class MainActivity extends AppCompatActivity {
public WhatsApp2 whatsApp2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void whatsapp(View view) {
whatsApp2 = new WhatsApp2();
whatsApp2.whatsappSend();
}
}
It Catch
an exception error in the WhatsApp2 class as:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference