Search code examples
androidmethod-invocation

Calling method available in the activity


I am trying to call a method available in a Activity from a java file.

The calling is made fine and the control transfers to the function by this code in the java file.

  myActivity my = new myActivty();
  myActivity.method1();

Now my problem is i cant able to give a toast message or display the alertdialog, Its giving null pointer exception when im using the Toast message,

07-20 15:13:00.836: ERROR/AndroidRuntime(418): java.lang.NullPointerException

Am i doing right?

Where am i wrong?

Help will be greatly appreciated.


Solution

  • Toast needs Context to show up. You're trying to show toast but you have created Activity without Context. Pass instance of working Activity to create dialog or show toast.