I'm a noob to android and i am having an issue calling a method from another class. The method works works fine when called from within its own class, but i get a nullpointerexception when i call it from another class. Any help would be greatly appreciated. Here is my code;
Calling method in class1 from class2:
BottlesActivity inst = new BottlesActivity();
inst.call0();
Method in class 1:
public void call0() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:1234567890"/*+phonenumber0*/));
startActivity(callIntent); //<--This line causes nullpointerexception
} catch (ActivityNotFoundException activityException) {
Log.e("dialing-example", "Call failed", activityException);
}
}
Here is my Logcat
09-06 20:51:33.237: E/AndroidRuntime(18192): java.lang.NullPointerException
09-06 20:51:33.237: E/AndroidRuntime(18192): at android.app.Activity.startActivityForResult(Activity.java:2893)
09-06 20:51:33.237: E/AndroidRuntime(18192): at android.app.Activity.startActivity(Activity.java:3003)
09-06 20:51:33.237: E/AndroidRuntime(18192): at com.bryanjrichardson.GSCC.BottlesActivity.call0(GoldandSilverCoinCalculatorActivity.java:857)
09-06 20:51:33.237: E/AndroidRuntime(18192): at com.bryanjrichardson.GSCC.SimpleItemizedOverlay$1.onClick(SimpleItemizedOverlay.java:204)
09-06 20:51:33.237: E/AndroidRuntime(18192): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:174)
09-06 20:51:33.237: E/AndroidRuntime(18192): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 20:51:33.237: E/AndroidRuntime(18192): at android.os.Looper.loop(Looper.java:130)
09-06 20:51:33.237: E/AndroidRuntime(18192): at android.app.ActivityThread.main(ActivityThread.java:3859)
09-06 20:51:33.237: E/AndroidRuntime(18192): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 20:51:33.237: E/AndroidRuntime(18192): at java.lang.reflect.Method.invoke(Method.java:507)
09-06 20:51:33.237: E/AndroidRuntime(18192): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-06 20:51:33.237: E/AndroidRuntime(18192): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-06 20:51:33.237: E/AndroidRuntime(18192): at dalvik.system.NativeStart.main(Native Method)