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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:15:47+00:00 2026-06-06T04:15:47+00:00

I keep getting 21002 ‘java.lang.NullPointerException’ errors from Apple when I try to test my

  • 0

I keep getting 21002 ‘java.lang.NullPointerException’ errors from Apple when I try to test my In-App Purchases in the sandbox. This is what I have done:

  • Set up the In-App Purchase products in iTunes Connect. I can successfully retrieve them via StoreKit.
  • Set up test user in iTunes Connect.
  • Application starts up, downloads the available In-App Purchase products, I trigger the In-App Purchase and Apple responds with the transactionReceipt, which I base64-encode on the iPhone and send to my C#/ASP.NET server.
  • The server puts the received string into JSON (I tried it both with NewtonSoft.Json and manually) and sends the JSON to Apple:

var json = "{ 'receipt-data': '" + receipt + "'}";

OR:

var json = new JObject(new JProperty("receipt-data", receipt)).ToString();

and then:

var webRequest = System.Net.HttpWebRequest.Create("https://sandbox.itunes.apple.com/verifyReceipt");
webRequest.ContentType = "text/plain";
webRequest.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(receipt);
webRequest.ContentLength = byteArray.Length;
using (var stream = webRequest.GetRequestStream())
{
    stream.Write(byteArray, 0, byteArray.Length);
    stream.Flush();
}

var resp = webRequest.GetResponse();
if (resp != null)
{
    using (var sr = new System.IO.StreamReader(resp.GetResponseStream()))
    {
        var result = sr.ReadToEnd().Trim();
        var iapResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<AppleIapResponse>(result);
        // always getting '21002' 'java.lang.NullPointerException'
    }
}

I tried everything: changing the ContentType, the JSON formatting, the encoding….

Any hints?

  • 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-06-06T04:15:48+00:00Added an answer on June 6, 2026 at 4:15 am

    It’s a simple bug in the code, I was writing the receipt into the POST, not the JSON:

    byte[] byteArray = Encoding.UTF8.GetBytes(json);
                                              ^^^^
    

    The wall hurts from banging my head against it..

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

Sidebar

Related Questions

I keep getting compiler errors when I try to access flashVars in an AS3
I keep getting emails from people and companies wanting to release my Android app
I keep getting a 'List does not exist' error whenever I try and use
I keep getting this error when I try to commit a group of executed
I keep getting errors that my functions have been defined multiple times. Of course
I keep getting this error when I try to build my solution. I've tried
Keep getting these errors while trying to compile an c++ class program. testStock.cpp: In
I keep getting the same error when I try to set an attribute but
I keep getting the following error: $ ./test.py -bash: ./test.py: cannot execute binary file
I keep getting this error from my code and I have no idea what

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.