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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:49:48+00:00 2026-05-28T15:49:48+00:00

Colleagues, I have the such question: 1. In my first class I have the

  • 0

Colleagues, I have the such question:
1. In my first class I have the

public class parseYouTubeAndYahoo extends AsyncTask<String, Void, List<VideoDataDescription>>

to parse data from internet. But I need to call execute() method of this class from another class. While trying to right such code:

new MainActivity.parseYouTubeAndYahoo().execute("someURL"); 

I have the next error message from Eclipse

No enclosing instance of type MainActivity is accessible. Must qualify the allocation with an enclosing instance of type MainActivity (e.g. x.new A() where x is an instance of MainActivity).

and really this problem is shrouded in fog for me. So, how to call this method from another class?

  • 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-28T15:49:49+00:00Added an answer on May 28, 2026 at 3:49 pm

    In terms of the actual error here, if parseYouTubeAndYahoo class is a non-static inner class inside of your Activity, then you need an instance of the enclosing class in order to instantiate the inner class. So, you’ll need:

    MainActivity myActivity = new MainActivity();
    MainActivity.parseYouTubeAndYahoo asyncTask = myActivity.new parseYouTubeAndYahoo();
    

    However….

    You really shouldn’t be instantiating non-static inner classes of your Activities from outside of the Activity because in order to instantiate a non-static innner class, you have to actually instantiate the enclosing class, which, in this case, is the Activity. Activities are meant to be started, not instantiated via new. If you have an AsyncTask that you’d like to use in different places, then create a new top-level class that extends from AsyncTask.

    (For an example of creating reusable AsyncTasks, see: https://github.com/levinotik/ReusableAsyncTask)

    Note that the syntax you’ve tried to use WOULD work if you needed to grab a static nested class. This is because in such a case, the outer class is really just acting as a namespace, but the nested class, because its static, does not actually need a reference to an instance of the outer class. Thus:

    OuterClass.StaticNestedClass nestedObject =
         new OuterClass.StaticNestedClass();
    

    is the proper syntax for getting an instance of a static nested class.

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

Sidebar

Related Questions

Colleagues, I have the divs: <!-- question 0 --> <div id=question 0> <!-- stars
Me and my colleagues have a question regarding SQL Server 2008 query length and
Colleagues have been touting the wonders of maven and its magical dependency stuff but
We (my colleagues) have a messy 12 y.o. mature app that is GUI-based, and
I have some projects on bzr code repositories shared with colleagues. Problem is, I
I have a .net application that is not working on a colleagues computer (he
I have quite a lot of C++ legacy code modules from my colleagues, unfortunately
I have a working C2DM project, atm. I have me and my colleagues phones
I've got a couple of colleagues who love Access and have lots of important
I have implemented an insertion sort in a double link list (highest to lowest)

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.