Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:40:47+00:00 2026-05-27T18:40:47+00:00

I have a project (in Eclipse) which I’ve turned into an Android Project Library

  • 0

I have a project (in Eclipse) which I’ve turned into an Android Project Library so as to re-use some of the code in another similar project. I think I’ve shot myself in the foot however as I’m getting the error:

Unable to start activity ComponentInfo{com.test.scroller1/com.lib.scrolltest.ScrollTestActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.lib.scrolltest.resAppVars

com.lib.scrolltest is my Project Library which instantiates a class extending Application (resAppVars). In the onCreate() method I call:

mRav = (resAppVars) getApplicationContext ();

This way, I can use methods in the mRav object which would otherwise be a lot of duplicated code in other classes (such as passing a query to a generic select statement which returns an ArrayList of results).

What’s the problem here? It seems I’ve hit a limitation in the way I’ve implemented the Application class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:40:48+00:00Added an answer on May 27, 2026 at 6:40 pm

    Calling getApplicationContext() returns the Application object for the current application (i.e. the application that owns the activity that onCreate() is running inside of).

    Unless you’re doing something strange, you don’t get to pick which Application class is used. There’s even a note in the documentation for Application saying not to do this:

    There is normally no need to subclass Application. In most situation,
    static singletons can provide the same functionality in a more modular
    way. If your singleton needs a global context (for example to register
    broadcast receivers), the function to retrieve it can be given a
    Context which internally uses Context.getApplicationContext() when
    first constructing the singleton.

    You should just create a regular shared class inside of your library project. Or if you don’t have a need for the special functionality library projects offer, you can also just use a regular .jar file.

    And if you need shared state, just make it a singleton. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project in Eclipse (Indigo but similar in Helios) which has files
I have a project in Eclipse which mixes native and Java code using CDT
I have some repositories on a svn server which include an Eclipse project. In
I have findbugs plugin for eclipse which when run on my project will show
I have an Android project and Eclipse is telling me my project has an
I have a source code of an OpenSource project which I get from SVN.
I have a remote project in Eclipse which was created through RSE's 'Create Remote
I have a C++ project on eclipse which compiles and runs fine from eclipse,
I have a project which runs fine from within Eclipse. But when I export
I am using Eclipse Indigo RC4 with EGit (bundled). I have a project which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.