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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:57:44+00:00 2026-05-31T20:57:44+00:00

i need to use my application class inside my thread which is started with

  • 0

i need to use my application class inside my thread which is started with InterService.
in my IntentService i have the following code:

    protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra("receiver");
    context = getBaseContext();
    app = (AppLoader)getApplicationContext();
    ConnectionThread thread = new ConnectionThread(receiver, context, app.getNewApp());

this is my Thread:

    public ConnectionThread (ResultReceiver receiver, Context context, AppLoader app)
    {

      this.receiver = receiver;
      this.context = context;
      this.activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
      this.app = app;
    }

    @Override
    public void run() {
    Log.d("ConnectionThread","Starting Server Connection");
        try {
            while(isThereActivityRunning()) {
                if(app.isInternetOn())
                {
                    Log.d("ConnectionThread", app.getText());
                    results = sendGetMessage();
                    b.putString("results", results);
                    receiver.send(2, b);
                }

this is my application:

public class AppLoader extends Application{
private AppLoader newApp;

public void onCreate()
{
  super.onCreate();
}

public AppLoader getNewApp()
{
  if(newApp == null)
     newApp = new AppLoader();   
  return newApp;    
}

i get a java.lang.NullPointerException and i can’t figure out why..

  • 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-31T20:57:45+00:00Added an answer on May 31, 2026 at 8:57 pm

    You can’t create your own Application instance, i.e.

    newApp = new AppLoader();

    is not meant to be called. Android creates the app for you, or at least it does if you declared your application class in the manifest, i.e.

    <application ... android:label="@string/app_name" android:name="AppLoader" android:debuggable="true">

    It will compile but you won’t have access to anything that an Android-instantiated application normally would.

    Assuming you have the manifest as above, you already have access to the application instance by calling:

    app = (AppLoader)getApplicationContext();

    so use that and delete the getNewApp() method.

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

Sidebar

Related Questions

I have an application where I need to use 'Basic Authentication'; however, in order
I have to do the following, when a class is instantiated I need to
I am developing an iPhone application in which I need to use Facebook's FQL
I have a WPF application which I need to integrate with WinForms. As suggested
I need to use this enum in my C# application, but it won't let
I need to use one logical PGM based multicast address in application while enable
I need to use a dll in my asp.net application. How do I load
I need to use a third party .jar lib in my application: unfortunately the
I need to use Integer Linear Programming API/Tool for my application. Though my application
I need to use the RGBRast software renderer for a DirectX application I'm developing.

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.