“No enclosing instance of type” error while calling method from another class in Android

后端 未结 4 1914
庸人自扰
庸人自扰 2020-11-29 06:33

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

public class parseYouTubeAndYahoo extends AsyncTask

        
4条回答
  •  温柔的废话
    2020-11-29 07:23

    I guess your parseYouTubeAndYahoo class is an inner class in class MainActivity, in Java, you should instaniate an object of the inner class by new MainActivity().new parseYouTubeAndYahoo(), so call that method like this new MainActivity().new parseYouTubeAndYahoo().execute("someURL");

    I also guess MainActivity extends the Activity class, so I think the answer should be this.new parseYouTubeAndYahoo().execute("someURL"); when you just call this method inside your MainActivity class.

提交回复
热议问题