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 8511885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:07:50+00:00 2026-06-11T04:07:50+00:00

I’m trying to create global variables in my application by creating a subclass in

  • 0

I’m trying to create global variables in my application by creating a subclass in android.app.Application. I’ve followed some tutorials on the internet, but I can’t seem to get it working. Eclipse is not giving me any errors, but when I start the application I get the following error: Unfortunately, Application has stopped.

Another person asked the same question on Stackoverflow, but this solution does not seem to work for me.

Here are my application files, any help would be greatly appreciated!

MainActivity.java

package com.app.app;

import org.apache.http.cookie.Cookie;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

TextView mTxtvName;

String cookie;
String username;
Cookie theRealCookie;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.overzichttablayout);

    mTxtvName = (TextView) findViewById(R.id.txtvName);

    Globals global = (Globals)getApplication();
    String username = global.getVariable("globUsername");
    String cookie = global.getVariable("globCookie");

    mTxtvName.setText(username);
}

}

Globals.java

package com.app.app;

import android.app.Application;

public class Globals extends Application {

private String globCookie = "null";
private String globUsername = "null";

public String getVariable(String someName) {
    if(someName == "globCookie")
    {
        return globCookie;
    }
    else if(someName == "globUsername")
    {
        return globUsername;
    }
    else
    {
        return null;
    }
}

public void setVariable(String someName, String someVariable) {
    if(someName == "globCookie")
    {
        this.globCookie = someVariable;
    }
    else if(someName == "globUsername")
    {
        this.globUsername = someVariable;
    }
}
}

Application Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.app"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" 
         android:theme="@android:style/Theme.Light.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="OverviewActivity" android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
</application>
<application android:name="Globals" android:icon="@drawable/ic_launcher" android:label="@string/app_name" />

</manifest>

Log Cat (shortend)

08:51:53.783: D/AndroidRuntime(1650): Shutting down VM
08:51:53.783: W/dalvikvm(1650): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08:51:53.863: E/AndroidRuntime(1650): FATAL EXCEPTION: main
  • 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-11T04:07:52+00:00Added an answer on June 11, 2026 at 4:07 am

    I suspect the error is because you declared a second <application /> tag

    You should have the Globals declared in the first <application />tag

    <application
        android:name="Globals" 
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
    

    And this line, delete:

    <application android:name="Globals" android:icon="@drawable/ic_launcher" android:label="@string/app_name" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.