0

Hello my static method works when i call it first time but when i call it more than once its giving me strange error. Please help me in resolving this error

My Method

 public static void XVD(String string){
        String youtubeLink = "https://www.website.com/data?v="+string;
        new DataExtractor(MainActivity.context) {
            @Override
            public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {
                if (ytFiles != null) {


                }
            }
        }.extract(youtubeLink, true, true);

    }

Error (on second call to above method)

 java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getCacheDir()' on a null object reference
Sunil Meena
  • 481
  • 3
  • 10
  • 19
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Benjamin Urquhart May 16 '19 at 21:31
  • No one knows MainActivity.context and DataExtractor is. But as a common bad pattern, static Context (MainActivity.context) is a reason. Null pointer will happen if it is null. – ytRino May 17 '19 at 02:37

0 Answers0