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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:06:55+00:00 2026-05-27T14:06:55+00:00

I have a few things that need to be done asynchronously during my application’s

  • 0

I have a few things that need to be done asynchronously during my application’s startup process. I’ve created an abstract class that derives from AsyncTask which implements things common to these loading tasks:

protected abstract class LoadTask extends AsyncTask<Object, Void, Object>{
    MainActivity activity;
    void detach(){
        activity = null;
    }
    void attach(MainActivity a){
        activity = a;
    }

    public LoadTask(MainActivity a){
        super();
        attach(a);
    }

    public abstract boolean shouldRun();

    @Override
    protected void onPostExecute(Object result){
        activity.onFinishLoad(this.getClass(), result);
    }
}

Following is one particular implementation of a concrete subclass:

public class ItemInfoLoadTask extends LoadTask{

    public ItemInfoLoadTask(MainActivity a){
        super(a);
    }

    public boolean shouldRun(){
        return should_reload("items", item_info_path);
    }

    @Override
    protected Object doInBackground(Object ... params) {
        setProgressMessage("Reading item info...");
        JSONObject result = loadItemInfo();
        return result;
    }

    private JSONObject loadItemInfo(){
        return Util.parseJSONObject(item_info_path);
    }
}

And here is the code that calls these from within the onCreate() method of my activity:

Log.v(TAG, c.getName());
Class[] types = {MainActivity.class};
Constructor construct = c.getConstructor(types);
task = (LoadTask)(construct.newInstance(this));

And here is the log:

12-17 10:26:25.750: V/MainActivity(25188): com.mycompany.mypackage.MainActivity$ItemInfoLoadTask
12-17 10:26:25.760: E/MainActivity(25188): this shouldn't happen
12-17 10:26:25.760: E/MainActivity(25188): java.lang.NoSuchMethodException: <init> [class com.mycompany.mypackage.MainActivity]
12-17 10:26:25.760: E/MainActivity(25188):        at java.lang.ClassMembers.getConstructorOrMethod(ClassMembers.java:235)
12-17 10:26:25.760: E/MainActivity(25188):        at java.lang.Class.getConstructor(Class.java:459)
12-17 10:26:25.760: E/MainActivity(25188):        at com.mycompany.mypackage.MainActivity.onCreate(MainActivity.java:80)
12-17 10:26:25.760: E/MainActivity(25188):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
12-17 10:26:25.760: E/MainActivity(25188):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
12-17 10:26:25.760: E/MainActivity(25188):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
12-17 10:26:25.760: E/MainActivity(25188):        at android.app.ActivityThread.access$1500(ActivityThread.java:122)
12-17 10:26:25.760: E/MainActivity(25188):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
12-17 10:26:25.760: E/MainActivity(25188):        at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 10:26:25.760: E/MainActivity(25188):        at android.os.Looper.loop(Looper.java:132)
12-17 10:26:25.760: E/MainActivity(25188):        at android.app.ActivityThread.main(ActivityThread.java:4028)
12-17 10:26:25.760: E/MainActivity(25188):        at java.lang.reflect.Method.invokeNative(Native Method)
12-17 10:26:25.760: E/MainActivity(25188):        at java.lang.reflect.Method.invoke(Method.java:491)
12-17 10:26:25.760: E/MainActivity(25188):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
12-17 10:26:25.760: E/MainActivity(25188):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
12-17 10:26:25.760: E/MainActivity(25188):        at dalvik.system.NativeStart.main(Native Method)

I can’t figure out what I’m doing wrong. If it matters any(although I can’t see why it should), LoadTask and ItemInfoLoadTask are inner classes in MainActivity

  • 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-27T14:06:55+00:00Added an answer on May 27, 2026 at 2:06 pm

    Non-static inner classes contain implicit reference to the instance of the enclosing class. All constructors of such inner classes take reference to the instance of enclosing class as an argument.

    A simple example:

    import java.lang.reflect.*;
    
    class Foo {
        class Bar {
            public Bar(int a) {
            }
        }
    
        public static void main(String[] args) {
            for(Constructor c: Bar.class.getDeclaredConstructors()) {
                System.out.println(c);
            }   
        }
    }
    

    prints public Foo$Bar(Foo,int) – note the first Foo parameter.
    The javap tool can show information about structure – declared fields, methods and constructors of Foo$Bar.class:

    Compiled from "Foo.java"
    class Foo$Bar extends java.lang.Object{
        final Foo this$0;
        public Foo$Bar(Foo, int);
    }
    

    Here you can see this implicit reference to the parent. JVM doesn’t know about inner classes so the compiler has to introduce synthetic methods and fields to achieve required behavior. It is usually remain unnoticed until you need something like reflection.

    In your particular case you can either make your inner classes static so there will be no implicit reference or remove explicit reference to the MainActivity.

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

Sidebar

Related Questions

I have a few things going on that need to be done one after
I have a few things that I cannot find a good way to perform
I have an asp.net website that uses forms authentication. There are a few things
So I have done a few minor things with web services and had some
I have an application that I need to query lifetables (for insurance calculation). I
I have a few different things open in the terminal whenever I'm developing --
Ok, a few things I'm not quite sure about. For starters: I have a
I'm working in C, and I have to concatenate a few things. Right now
To keep things simple, we have a few aspx pages... Page1.aspx - resets Session
I have few asynchronous tasks running and I need to wait until at least

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.