title: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser
body: <p>I am getting this error.I am new to android studio and i need to create this plugin for unity to install an apk at runtime</p>
  
  <p>Error - Attempt to invoke virtual method 'android.content.Context Android.content.Context.getApplicationContext()' on a null object reference</p>
  
  <p>Plugin Class -    </p>
  
  <pre><code>package com.example.unitypluginappinstall;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.support.v4.content.FileProvider;
  
  import java.io.File;
  
  public class PluginClass extends Activity  {
  static String errMessage;
  
  public static String InstallApp(String ApkPath){
   try {
       errMessage = "test";
       File toInstall = new File(ApkPath);
       Uri apkUri = FileProvider.getUriForFile(ContextClass.context(), 
  ContextClass.context().getApplicationContext().getPackageName() + 
  ".fileprovider", toInstall);
       Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
       intent.setData(apkUri);
       intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
       ContextClass.context().startActivity(intent);
   }
   catch (Exception e){
      errMessage = e.getMessage();
   }
      return errMessage;
  }
  
  }
  </code></pre>
  
  <p>ContextClass - </p>
  
  <pre><code>package com.example.unitypluginappinstall;
  
  import android.app.Application;
  import android.content.Context;
  
  public class ContextClass extends Application {
  private  static ContextClass instance;
  
  public ContextClass(){
      instance = this;
  }
  
  public static ContextClass instance(){
      return instance;
  }
  
  public static Context context() {
      return instance.getApplicationContext();
  }
  }
  </code></pre>
  
  <p>Manifest File - </p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  
  package="com.example.unitypluginappinstall"&gt;
  
  &lt;application android:allowBackup="true" android:label="@string/app_name"
      android:supportsRtl="true"&gt;
      &lt;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="${applicationId}.fileprovider"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/filepaths"&gt;&lt;/meta-data&gt;
      &lt;/provider&gt;
      android:name=".ContextClass"&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>PluginWrapper:</p>
  
  <pre><code>public class PluginWrapper : MonoBehaviour {
  string savePath;
  void Start () {
      savePath = Path.Combine(Application.persistentDataPath, "data");
      savePath = Path.Combine(savePath, "applaunchtest.apk");
      Install();
  }
  
  void Install(){
  try
      {
          //Install APK
          GameObject.Find("TextDebug").GetComponent&lt;Text().text"Installing...";
          var plugin = new 
     AndroidJavaClass("com.example.unitypluginappinstall.PluginClass");
          GameObject.Find("TextDebug").GetComponent&lt;Text&gt;().text = 
     plugin.CallStatic&lt;string&gt;("InstallApp", savePath);
      }
      catch(Exception e)
      {
          GameObject.Find("TextDebug").GetComponent&lt;Text&gt;().text = e.Message;
      }
  }
  }
  </code></pre>
  
  <p><strong>EDIT</strong> - 
  Plugin Class</p>
  
  <pre><code>package com.example.unitypluginappinstall;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.support.v4.content.FileProvider;
  
  import java.io.File;
  
  public class PluginClass extends Activity  {
  static String errMessage;
  
  public static String InstallApp(Context context, String ApkPath){
   try {
       errMessage = "test";
       File toInstall = new File(ApkPath);
       Uri apkUri = FileProvider.getUriForFile(context,
               context.getApplicationContext().getPackageName() +
                       ".fileprovider", toInstall);
       Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
       intent.setData(apkUri);
       intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
       context.startActivity(intent);
   }
   catch (Exception e){
      errMessage = e.getMessage();
   }
      return errMessage;
  }
  
  }
  </code></pre>
  
  <p>Plugin Wrapper - </p>
  
  <pre><code>public class PluginWrapper : MonoBehaviour {
  string savePath;
  void Start () {
      savePath = Path.Combine(Application.persistentDataPath, "data");
      savePath = Path.Combine(savePath, "applaunchtest.apk");
      Install();
  }
  
  void Install(){
  try
      {
          //Install APK
  AndroidJavaClass unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
          AndroidJavaObject unityActivity = unityClass.GetStatic&lt;AndroidJavaObject&gt;("currentActivity");
          AndroidJavaObject unityContext = unityActivity.Call&lt;AndroidJavaObject&gt;("getApplicationContext");
          GameObject.Find("TextDebug").GetComponent&lt;Text().text"Installing...";
          var plugin = new 
     AndroidJavaClass("com.example.unitypluginappinstall.PluginClass");
          GameObject.Find("TextDebug").GetComponent&lt;Text&gt;().text = 
     plugin.CallStatic&lt;string&gt;("InstallApp",unityContext, savePath);
      }
      catch(Exception e)
      {
          GameObject.Find("TextDebug").GetComponent&lt;Text&gt;().text = e.Message;
      }
  }
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p><a href="https://i.stack.imgur.com/YZ453.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YZ453.jpg" alt="Plugins/Android"></a></p>