Reputation: 55
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.
Upvotes: 3
Views: 284
Reputation: 91
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.
Upvotes: 1
Reputation: 9585
You could try using getClass().getName() on the instance to see actually which type is it and then do the proper cast.
Upvotes: 0
Reputation: 86948
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.
Upvotes: 2