IAP error NullReferenceException: Object reference not set to an instance of an object

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing;

public class IapManager : MonoBehaviour, IStoreListener
{
public static IapManager Instance { set; get; }
public main gameMgrs;
private static IStoreController m_StoreController;
private static IExtensionProvider m_StoreExtensionProvider;

public const string productId10 = "marble_10_kor";
void Start()
{
    if (m_StoreController == null)
    {
        InitializePurchasing();
    }
}

public void InitializePurchasing()
{
    if (IsInitialized())
    {
        return;
    }
    var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

    builder.AddProduct(productId10, ProductType.Consumable);
 
    UnityPurchasing.Initialize(this, builder);
}

private bool IsInitialized()
{
    return m_StoreController != null && m_StoreExtensionProvider != null;
}

public void Buy1()
{
    BuyProductID(productId10);
}

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));

    switch (args.purchasedProduct.definition.id)
    {
        case productId10:

            Debug.Log("10개 구매완료");
            gameMgrs.cash1();
            break;
    }

    return PurchaseProcessingResult.Complete;
}

public void buy1()
{
Debug.Log(1);
IapManager.Instance.Buy1();
Debug.Log(2);
}
Debug 1

I want use IAP. but have some error
NullReferenceException: Object reference not set to an instance of an object

Did I do something wrong?

I also encounter this problem on android.
My unity version is 5.5.0f3…
Anyone help?

The tutorial is confusing. I just came into the same problem today. After researching and looking around the whole day. I could finally figure out what’s wrong.
m_StoreController is indeed not initialized until the IStoreListener method returns it.

    public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
       m_StoreController = controller;
      }

These 3 lines of code should be put into awake as well or they would never be called and thus m_StoreController will never get initialized.

 var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
 builder.AddProduct(productId10, ProductType.Consumable);
 UnityPurchasing.Initialize(this, builder);