title: Java.io.FileNotFoundException "URL"
body: <p>I'm trying to create and android app that can pay through credit card using master card api. I' following this tutorial  ->><a href="https://developer.mastercard.com/portal/pages/viewpage.action?pageId=14876685" rel="nofollow">https://developer.mastercard.com/portal/pages/viewpage.action?pageId=14876685</a>  but it says that the url was not found. </p>
  
  <p>this is the codes i used:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy); 
  
          ((Button) findViewById(R.id.submit)).setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Context context = getApplicationContext();
                  String endPoint = "https://api.mastercard.com/payments/v1/purchase?Format=XML";
                  EditText cardNumberInput = (EditText) findViewById(R.id.cardNumberInput);
                  EditText expirationMonthInput = (EditText) findViewById(R.id.expirationMonthInput);
                  EditText expirationYearInput = (EditText) findViewById(R.id.expirationYearInput);
                  EditText cvvInput = (EditText) findViewById(R.id.cvvInput);
                  EditText cardHolderNameInput = (EditText) findViewById(R.id.cardHolderNameInput);
                  EditText amountInput = (EditText) findViewById(R.id.amountInput);
  
                  final double amount = Float.valueOf(amountInput.getText().toString());
                  final String currency = "USD";
                  final String companyId = "ComID";
                  final String companyPassword = "ComPass";
                  final String messageId = "001";
                  final String settlementId = "011";
                  final String cardHolderName = cardHolderNameInput.getText().toString();
                  final String accountNumber = cardNumberInput.getText().toString();
                  final String expiryMonth = expirationMonthInput.getText().toString();
                  final String expiryYear = expirationYearInput.getText().toString();
                  final String securityCode = cvvInput.getText().toString();
                  try {
                      // Send data
                      URL url = new URL(endPoint);
                      URLConnection conn = url.openConnection();
                      conn.setDoOutput(true);
                      conn.setDoInput(true);
                      OutputStreamWriter request = new OutputStreamWriter(conn.getOutputStream());
                                  // Create the XML to post
                      request.append("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;");
                      request.append("&lt;PurchaseRequest&gt;");
                      request.append("&lt;MerchantIdentity&gt;");
                      request.append("&lt;CompanyId&gt;");
                      request.append(companyId);
                      request.append("&lt;/CompanyId&gt;");
                      request.append("&lt;CompanyPassword&gt;");
                      request.append(companyPassword);
                      request.append("&lt;/CompanyPassword&gt;");
                      request.append("&lt;/MerchantIdentity&gt;");
                      request.append("&lt;Reference&gt;");
                      request.append("&lt;MessageId&gt;");
                      request.append(messageId);
                      request.append("&lt;/MessageId&gt;");
                      request.append("&lt;SettlementId&gt;");
                      request.append(settlementId);
                      request.append("&lt;/SettlementId&gt;");
                      request.append("&lt;/Reference&gt;");
                      request.append("&lt;Amount&gt;");
                      request.append("&lt;Currency&gt;");
                      request.append(currency);
                      request.append("&lt;/Currency&gt;");
                      request.append("&lt;Value&gt;");
                      request.append(Double.toString(amount));
                      request.append("&lt;/Value&gt;");
                      request.append("&lt;/Amount&gt;");
                      request.append("&lt;FundingCard&gt;");
                      request.append("&lt;CardholderName&gt;");
                      request.append(cardHolderName);
                      request.append("&lt;/CardholderName&gt;");
                      request.append("&lt;AccountNumber&gt;");
                      request.append(accountNumber);
                      request.append("&lt;/AccountNumber&gt;");
                      request.append("&lt;ExpiryMonth&gt;");
                      request.append(expiryMonth);
                      request.append("&lt;/ExpiryMonth&gt;");
                      request.append("&lt;ExpiryYear&gt;");
                      request.append(expiryYear);
                      request.append("&lt;/ExpiryYear&gt;");
                      request.append("&lt;SecurityCode&gt;");
                      request.append(securityCode);
                      request.append("&lt;/SecurityCode&gt;");
                      request.append("&lt;/FundingCard&gt;");
                      request.append("&lt;/PurchaseRequest&gt;");
                      request.flush();
  
                      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                      DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                      Document doc = docBuilder.parse(conn.getInputStream());
                      Node transactionResponseNode = doc.getElementsByTagName("TransactionResponse").item(0);
                      // Test for approval.
                      String response = transactionResponseNode.getNodeValue().trim().toUpperCase();
                      Log.d("**********Response", ""+response);
                      if (response.equals("APPROVED") == true) {
                          request.close();
                          String text = "The payment processed successfully.  PHP" + amountInput.getText().toString()
                                      + " was charged to the account.";
                          Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
                                  toast.show();
                      } else if (response.equals("DECLINED")) {
                          String text = "The payment was declined.";
                          Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
                          toast.show();
                      } else if (response.equals("ERROR")) {
                          String text = "Error Processing Payment.";
                          Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
                          toast.show();
                      }
                  } catch (MalformedURLException e) {
                      String text = "Error";
                      Toast toast = Toast.makeText(context, ""+e, Toast.LENGTH_LONG);
                      toast.show();
                  } catch (IOException e) {
                      String text = "Error";
                      Toast toast = Toast.makeText(context, ""+e, Toast.LENGTH_LONG);
                      toast.show();
                  } catch (ParserConfigurationException e) {
                      String text = "Error";
                      Toast toast = Toast.makeText(context, ""+e, Toast.LENGTH_LONG);
                      toast.show();
                  } catch (SAXException e) {
                      String text = "Error";
                      Toast toast = Toast.makeText(context, ""+e, Toast.LENGTH_LONG);
                      toast.show();
                  }
              }
          });
      }
  }
  </code></pre>
  
  <p>any thoughts will help me a lot. Thanks.</p>
  
  <p>this is what log cat says:</p>
  
  <pre><code>05-22 11:20:58.129: D/**********Error2(1424): java.io.FileNotFoundException: https://api.mastercard.com/payments/v3/purchase?Format=XML
  </code></pre>