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

  • SEARCH
  • Home
  • 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 8518611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:01:37+00:00 2026-06-11T06:01:37+00:00

I know this has been asked before(and I have read lots of posts here

  • 0

I know this has been asked before(and I have read lots of posts here about them) but I can’t figure out what I’m doing wrong. I want to set some things up as global variables to use throughout my app. So I created a new folder (which I think created a new app?) with a class in it :

enter image description here

Which is all good. In the Global.java I have the following:

package com.directenquiries.assessment.tool.Globals;

import android.app.Application;
import android.os.Environment;

public class Global extends Application {
      public String foo;
      public String SDcard = Environment.getExternalStorageDirectory().getAbsolutePath();


    }

My Manifest file now looks like: (which I think might be the culprit?)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.directenquiries.assessment.tool"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".LoginPageActivity"
            android:label="@string/title_activity_login_page" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

    <application
       android:name="Global" 
       android:label="@string/app_name" >
    </application>


</manifest>

And I’m trying to call the variable back in my LoginPageActivity like:

String SDLoc = ((Global) this.getApplication()).foo;

        TextView obs = (TextView) findViewById(R.id.textView1);
        obs.setText(SDLoc);

But my app falls over with:

09-11 14:14:19.354: W/dalvikvm(5339): threadid=1: thread exiting with uncaught exception (group=0x40c4f1f8)
09-11 14:14:19.359: E/AndroidRuntime(5339): FATAL EXCEPTION: main
09-11 14:14:19.359: E/AndroidRuntime(5339): java.lang.ClassCastException: android.app.Application cannot be cast to com.directenquiries.assessment.tool.Globals.Global

Any help will be appreciated

  • 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-06-11T06:01:39+00:00Added an answer on June 11, 2026 at 6:01 am

    Modify public String foo to public final static String foo and than you can refere to as Global.foo.
    You don’t need to put Global class in another package.

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

Sidebar

Related Questions

I know this question has been asked here before, but I don't think those
I know this has been asked before, but nothing is working. I have signed
I know this has been asked before. But I have exhausted the options given
I know this has been asked before but I'd like to ask it here
I know this has been asked before, but I just can't seem to get
I know this has probably been asked before but I can't find a specific
I know this has probably been asked before but I can't seem to find
I know this question has been asked before, but I tried eveything and can't
I know this has been asked before but I have looked at every answer
I know this has been asked here before but my conditions are a little

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.