It is really hard to tell what the problem is, because we know nothing about the code which does any of the work, nor do we know the error you are getting. So any suggestions are a shot in the dark. It most likely is either different instances/class loaders being used when setting the context versus using it, or a timing issue, where the error message is sent before the code which sets the context. To fix that, try putting break points at key points in your code, and run the application in debug mode, looking for order of execution and the values of key objects. If you don't know how to do that, then pepper your code with identifying LogCat messages so you know when things occur by watching the LogCat output.
Here is a scheme that should work - no details just an outline of how things might be put together, such that your shared package (which could be used as a library rather than just a package) would have access to the ErrorManager and need no knowledge about anything platform specific.
First, lets do some architecture. The first thing we will need is an ErrorManagement construct. If there is not going to be shared code among the different platform implementations, then you minds well make it an interface. If there will be shared code, use an abstract class:
We will use a factory to distribute ErrorManagement instances to anyone who wants one. We want the factory to be generic, not platform specific, so we will create another interface which has a method which will deliver platform-specific ErrorManagement implementations to the factory (the factory is a single, go-to location anyone can reach to get an ErrorManagement instance, this interface will be used to generate platform-specific implementations):
Now we have everything we need for the factory that can be used to get ErrorManagement instances upon demand:
Any code in any package would use the following code to get an ErrorManagement instance and call its showErrorMessage() method:
Now we need the Android specific stuff. First, we need an Android specific ErrorManagement implementation that knows how to build the AlertDialog...
Then we need to create an ErrorManagementSource implementation to create and deliver the AndroidErrorManagement to the factory upon need. Since AndroidErrorManagement needs a Context, we will need to make sure it is created in a location that has access to an Android context. We also need to make sure it is created before any chance of needing to use it. In a desktop application, that might be the main() method or the constructor of your main class. But for Android, the Application instance's onCreate() method is a good place to start:
Now if you setup your manifest properly to use the Application class you created above as the app's Application scope, the AndroidErrorManagement instance will be created, an ErrorManagementSource which delivers that instance to all askers will be created and passed to ErrorManagementFactory, and the ErrorManagementFactory will be ready to distribute the AndroidErrorManagement instance to anyone who calls ErrorManagementFactory.getErrorManagement() as soon as the application is created (barring any typos or other errors).