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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:49:49+00:00 2026-05-30T19:49:49+00:00

Update 2 Logcat: 03-02 19:03:47.616: E/AndroidRuntime(881): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{TheTask}: java.lang.InstantiationException: .TheTask

  • 0

Update 2

Logcat:

03-02 19:03:47.616: E/AndroidRuntime(881): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{TheTask}: java.lang.InstantiationException:  .TheTask
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.os.Looper.loop(Looper.java:123)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-02 19:03:47.616: E/AndroidRuntime(881):  at java.lang.reflect.Method.invokeNative(Native Method)
03-02 19:03:47.616: E/AndroidRuntime(881):  at java.lang.reflect.Method.invoke(Method.java:507)
03-02 19:03:47.616: E/AndroidRuntime(881):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-02 19:03:47.616: E/AndroidRuntime(881):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-02 19:03:47.616: E/AndroidRuntime(881):  at dalvik.system.NativeStart.main(Native Method)
03-02 19:03:47.616: E/AndroidRuntime(881): Caused by: java.lang.InstantiationException: TheTask
03-02 19:03:47.616: E/AndroidRuntime(881):  at java.lang.Class.newInstanceImpl(Native Method)
03-02 19:03:47.616: E/AndroidRuntime(881):  at java.lang.Class.newInstance(Class.java:1409)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-02 19:03:47.616: E/AndroidRuntime(881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ProgressBar
        android:id="@+id/the_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
 <ListView
     android:id="@+id/android:list"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_weight="0.63" />
</LinearLayout>

TestingAsyncTask

//The class that starts the task
public class TestingAsyncTask extends ListActivity {

    private ProgressBar bar = null; 
    private ArrayList<String> data = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.thetask);
        bar = (ProgressBar) findViewById(R.id.the_progress);
        data.add("1");
        data.add("2");
        data.add("3");

        Log.d("create", ""+ data.size());

        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));
        new TheTask(this).execute((Void) null);     
    }

    public ArrayList<String> getData() {
        return data;
    } 
}

thetask.java async file

//The AsyncTask class
public class TheTask extends AsyncTask<Void, Void, List<String>> {

    Context c;

    public TheTask(Context c) {
        this.c = c;
    }   

    @Override
    protected void onPreExecute() {
        ((TestingAsyncTask) c).findViewById(R.id.the_progress).setVisibility(View.VISIBLE);
    }



    @Override
    protected List<String> doInBackground(Void... params) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ArrayList<String> res= new ArrayList<String>();
        res.add("a");
        res.add("b");
        res.add("c");
        Log.d("doinbacground", ""+ res.size());
        return res;
    }

    @Override
    protected void onPostExecute(List<String> result) {
        TestingAsyncTask activity = ((TestingAsyncTask) c);
        activity.getData().clear();
        activity.getData().addAll(result);
        ((ArrayAdapter)activity.getListAdapter()).notifyDataSetChanged();
        ((TestingAsyncTask) c).findViewById(R.id.the_progress).setVisibility(View.GONE);
    }

}

End Update 2

Update1:

Description Resource    Path    Location    Type
m_ProgressDialog cannot be resolved GrabUrlAsyncTask.java   
line 81 Java Problem
The field Main.m_orders is not visible   GrabUrlAsyncTask.javaline 79   
Java Problem
The field Main.m_ProgressDialogis not visible   GrabUrlAsyncTask.javaline 
80  Java Problem
The method notifyDataSetChanged() is undefined for the type ListAdapter GrabUrlAsyncTask.java   
line 82 Java Problem

Update:

@Override 
        protected void onPostExecute(List<Employee> result) 
        {            
            //showToast("You have to be connected to the internet for this application to work");   
            m_orders.clear();     
            m_orders.addAll(result);   
            progress.dismiss();
            mContext.m_adapter.notifyDataSetChanged();   
        } 

I’ve been working on an app and I’ve managed to get the AsyncTask to work fine when it’s an inner class, which means in the same main.java class and when i looked at the code and it look so hard to get into and i am planning of doing refactoring the code so that the AsyncTask will have its onw separate class.

i started to doing it but then it raised few questions like, how would i show the ProgressDialog box or toastText

can anbydoy give me some direction please?

here is my code:

public class Main extends ListActivity{

     @Override
     public void onCreate(Bundle savedInstanceState) 
     {
           ............
           .............
           new taskDoSomething().execute();


     } //

     private class taskDoSomething extends AsyncTask<Void, Void, List<Employee>> 
     {
           @Override 
      protected List<Surah> doInBackground(Void... params) 
      {
                //do some stuffs...
                try {
                     ///
                catch (Exception e)
                {
                   //
                }

            } 

            protected void onProgressUpdate(Void... values)
      {
              super.onProgressUpdate(values);         
         m_ProgressDialog.dismiss();  
            } 

            protected void onPostExecute(List<Employee> result)
      {
              m_orders.clear();     
        m_orders.addAll(result);   
        m_ProgressDialog.dismiss();
        m_adapter.notifyDataSetChanged();             
           }  
     } 
}
  • 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-30T19:49:50+00:00Added an answer on May 30, 2026 at 7:49 pm

    Create a constructor in your AsyncTask that takes a Context like this:

    private Context context; //field in your AsyncTask
    
    public taskDoSomething(Context context) {
        this.context = context;
    }
    

    and then in your activity where you create the task:

    new taskDoSomething(this).execute();
    

    Now in your AsyncTask you have a Context(that you can cast back to your activity) and you can use this context to show the things you want.

    EDIT:
    Cast the Context parameter to your class and then you can access all the fields for that class. For example if your m_orders is a public field in your class you can access it like bellow or you can make a getter/setter method for the m_orders :

    protected void onPostExecute(List<Employee> result) {
             Main activity = (Main) context;
             activity.m_orders.clear();     
             activity.m_orders.addAll(result);   
             m_ProgressDialog.dismiss();
             activity.getListAdapter().notifyDataSetChanged();             
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update based on @Tom solution: SongsManager.java public class SongsManager extends AsyncTask<Void, Void, ArrayList<HashMap<String, String>>>
UPDATE maybe changing the Bitmap size in the new Activity may fix the problem
Update: Solved, with code I got it working, see my answer below for the
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: giving a much more thorough example. The first two solutions offered were right
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
Update : Looks like the query does not throw any timeout. The connection is
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
UPDATE: Thanks to everyone for the responses. I didn't realize document.write() was deprecated. Add

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.