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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:57:31+00:00 2026-06-18T21:57:31+00:00

Been struggling with this for a while now. Basically i have extended the application

  • 0

Been struggling with this for a while now. Basically i have extended the application class so that it creates a simple linkedlist in the hope that this list would be accessible across various activities. But for can’t seem to get the information out of the linkedlist when i need it.

I’m not sure if this is even possible (although i don’t see why it wouldn’t) or if I am just making some stupid mistakes when dealing with the linkedlist.

Extending the appllication class (GlobalData)

package com.example.testing;

import java.util.LinkedList;
import android.app.Application;
import android.widget.Toast;

public class GlobalData extends Application {

public static LinkedList<String> EmployeeList;

@Override
public void onCreate(){
    super.onCreate();
    createLinkedList();
}

public void createLinkedList(){
    // create a linked list

    LinkedList<String> EmployeeList = new LinkedList<String>();
    String emp1 ="john", emp2="adam";
    EmployeeList.add(emp1);
    EmployeeList.add(emp2);

    String boo;
     boo = EmployeeList.getFirst();

    //This works, displays the name ok.
    Toast.makeText(getApplicationContext(), "("+boo+")" ,Toast.LENGTH_LONG).show();
}

}

The main where i would like to be able to access the linkedlist.

package com.example.testing;

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

public class MainActivity extends Activity {

protected GlobalData globalData;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get the application instance
    globalData = (GlobalData)getApplication();  

    String boo;
    boo = GlobalData.EmployeeList.getFirst();

    //This doesn't work & im not sure why.
    Toast.makeText(getApplicationContext(), "("+boo+")" ,Toast.LENGTH_LONG).show();     

}
}

Probably should mention that i’m just getting started with this stuff, so apologies if this is a completely idiotic question.

I can’t understand why I am not able to access the contents of that list, if i modify the script so that the GlobalData class contains a string variable the above code(with a few alterations) works fine. So why would the variable be accessible but the linked list not?

Thanks

  • 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-18T21:57:33+00:00Added an answer on June 18, 2026 at 9:57 pm

    In this line you are creating a new instance of the list instead of using the one you’ve created as a member of the class:

    LinkedList<String> EmployeeList = new LinkedList<String>();
    

    Simply change this line to :

    EmployeeList = new LinkedList<String>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for a while now. given a set of
I've been struggling with this issue for a while now. I have OpenCart 1.5.2.1
I've been struggling with this for a while. Basically, I want to have two
I have been struggling with this error for a while now and there seems
I have been struggling with this a while now. I implemented a basic IHttpHandler
I have been struggling with this for a while now and I cannot find
I have been struggling with this for a while now. I have a Master
Iv been struggling with this for a while now an I have exhausted all
I have been struggling with this for a while now, somehow JQuery is escaping
Hi all i have been struggling this for a while now! I have some

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.