I have VideoApplication class which extends Application class. I have created my other java class's object in this class so that I can pass it through activities.
public class VideoApplication extends Application {
private Client client;
public Client getClient(){
return client;
}
public void setClient(Client client){
this.client = client;
}
}
I have added following line in androidManifest file:
android.name=".VideoApplication".
But when I add the following line to my code(MainActivity.java), the application throws a ClassCastException exception.
VideoApplication appInstance = (VideoApplication)getApplicationContext();
Where am I going wrong? Please help.
You might be causing a ClassCastException. Try using getApplication() not getApplicationContext():
VideoApplication appInstance = (VideoApplication) getApplication();
Since you really want an Application object not a Context object.
Sure I am late to answer this but
android.name=".VideoApplication
doesn't seem right. I think it should be
android:name=".VideoApplication
I hope its not a typo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With