Dynamically instantiating AsyncTask from class object fails due to no constructor found
<p>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:</p>

<pre><code>protected abstract class LoadTask extends AsyncTask&lt;Object, Void, Object&gt;{
    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);
    }
}
</code></pre>

<p>Following is one particular implementation of a concrete subclass:</p>

<pre><code>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);
    }
}
</code></pre>

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

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

<p>And here is the log:</p>

<pre><code>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: &lt;init&gt; [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)
</code></pre>

<p>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</p>
