0

I have this exception "java.lang.ClassCastException: android.app.Application cannot be cast to com.utility.TablePlussAndroid" I do not understand why... thanks a lot for your help

package com.tableplustablet;
private com.utility.TablePlusAndroid session;

public class LoginActivity extends Activity {

    // ...

    // get session from Application                        
    session =  (TablePlusAndroid) this.getApplication(); // <--EXCEPTION
    session.setUserKey(userKey);
} 

// -------------------------------------------------------------

package com.utility;
import android.app.Application;

 //Save User Data in  application's context
 public class TablePlusAndroid extends Application{
private Long userKey;
private String userName;
private Long currentTableKey;  

    public Long getCurrentTableKey() {
        return currentTableKey;
}

    public void setCurrentTableKey(Long currentTableKey) {
        this.currentTableKey = currentTableKey;
    }
    public Long getUserKey(){ return userKey;}
    public void setUserKey(Long key){ userKey=key;}
    public String getUserName() { return userName; }
    public void setUserName(String userName) { this.userName = userName; }  
}
1
  • Can you point to the exact line of code that is giving the exception? That would make it easier to get help. Commented Dec 20, 2012 at 20:54

1 Answer 1

4

You need to use your application class in your AndroidManifest.xml file.

It should look like this:

<application android:name="application.package.and.class">
    <activity .... />
</application>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks! I missed to put android:name (it was a merge with another applicaion)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.