title: Paypal SDK and Android
body: <p>I'm trying to implement Paypal Payment in my app. I get the example from here : 
  <a href="https://github.com/paypal/PayPal-Android-SDK" rel="nofollow">https://github.com/paypal/PayPal-Android-SDK</a>.
  When I launch the app with eclipse everything is good.
  But when I try to add the activity, the xml file, and the manifest in my own app in Android Studio (V 0.6.0), an error appears since yesterday.
  I can't call my method onBuyPressed with the line android:onClick="onBuyPressed" in my button.
  I have this error : </p>
  
  <pre><code>06-09 20:57:45.851  10161-10161/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.IllegalStateException: Could not find a method onBuyPressed(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'buyItBtn'
              at android.view.View$1.onClick(View.java:3724)
              at android.view.View.performClick(View.java:4274)
              at android.view.View$PerformClick.run(View.java:17357)
              at android.os.Handler.handleCallback(Handler.java:615)
              at android.os.Handler.dispatchMessage(Handler.java:92)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4949)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NoSuchMethodException: onBuyPressed [class android.view.View]
              at java.lang.Class.getConstructorOrMethod(Class.java:460)
              at java.lang.Class.getMethod(Class.java:915)
              at android.view.View$1.onClick(View.java:3717)
              at android.view.View.performClick(View.java:4274)
              at android.view.View$PerformClick.run(View.java:17357)
              at android.os.Handler.handleCallback(Handler.java:615)
              at android.os.Handler.dispatchMessage(Handler.java:92)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4949)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>You can see my activity here : </p>
  
  <pre><code>package net.sparkeek.test.cubydroid.app;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.net.Uri;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Toast;
  
  import com.paypal.android.sdk.payments.PayPalAuthorization;
  import com.paypal.android.sdk.payments.PayPalConfiguration;
  import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
  import com.paypal.android.sdk.payments.PayPalItem;
  import com.paypal.android.sdk.payments.PayPalPayment;
  import com.paypal.android.sdk.payments.PayPalPaymentDetails;
  import com.paypal.android.sdk.payments.PayPalService;
  import com.paypal.android.sdk.payments.PaymentActivity;
  import com.paypal.android.sdk.payments.PaymentConfirmation;
  
  import org.json.JSONException;
  
  import java.math.BigDecimal;
  
  
  public class PaypalActivity extends ActionBarActivity {
  
      private static final String TAG = "paymentExample";
      /**
       * - Set to PaymentActivity.ENVIRONMENT_PRODUCTION to move real money.
       *
       * - Set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials
       * from https://developer.paypal.com
       *
       * - Set to PayPalConfiguration.ENVIRONMENT_NO_NETWORK to kick the tires
       * without communicating to PayPal's servers.
       */
      private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
  
      // note that these credentials will differ between live &amp; sandbox environments.
      private static final String CONFIG_CLIENT_ID = "credential from developer.paypal.com";
  
      private static final int REQUEST_CODE_PAYMENT = 1;
      private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
  
      private static PayPalConfiguration config = new PayPalConfiguration()
              .environment(CONFIG_ENVIRONMENT)
              .clientId(CONFIG_CLIENT_ID)
                      // The following are only used in PayPalFuturePaymentActivity.
              .merchantName("Hipster Store")
              .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
              .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_paypal);
          /*Button btnSouscription = (Button)findViewById(R.id.btnSouscription);
          btnSouscription.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  onBuyPressed(v);
              }
          });*/
  
          Intent intent = new Intent(this, PayPalService.class);
          intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
          startService(intent);
      }
  
  
      public void onBuyPressed(View v) {
          /*
           * PAYMENT_INTENT_SALE will cause the payment to complete immediately.
           * Change PAYMENT_INTENT_SALE to PAYMENT_INTENT_AUTHORIZE to only authorize payment and
           * capture funds later.
           *
           * Also, to include additional payment details and an item list, see getStuffToBuy() below.
           */
          PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);
  
          Intent intent = new Intent(PaypalActivity.this, PaymentActivity.class);
  
          intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
          startActivityForResult(intent, REQUEST_CODE_PAYMENT);
      }
  
      private PayPalPayment getThingToBuy(String paymentIntent) {
          return new PayPalPayment(new BigDecimal("1.75"), "USD", "hipster jeans",
                  paymentIntent);
      }
  
      /*
       * This method shows use of optional payment details and item list.
       */
      private PayPalPayment getStuffToBuy(String paymentIntent) {
          PayPalItem[] items =
                  {
                          new PayPalItem("old jeans with holes", 2, new BigDecimal("87.50"), "USD",
                                  "sku-12345678"),
                          new PayPalItem("free rainbow patch", 1, new BigDecimal("0.00"),
                                  "USD", "sku-zero-price"),
                          new PayPalItem("long sleeve plaid shirt (no mustache included)", 6, new BigDecimal("37.99"),
                                  "USD", "sku-33333")
                  };
          BigDecimal subtotal = PayPalItem.getItemTotal(items);
          BigDecimal shipping = new BigDecimal("7.21");
          BigDecimal tax = new BigDecimal("4.67");
          PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);
          BigDecimal amount = subtotal.add(shipping).add(tax);
          PayPalPayment payment = new PayPalPayment(amount, "USD", "hipster jeans", paymentIntent);
          return payment.items(items).paymentDetails(paymentDetails);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == REQUEST_CODE_PAYMENT) {
              if (resultCode == Activity.RESULT_OK) {
                  PaymentConfirmation confirm =
                          data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                  if (confirm != null) {
                      try {
                          Log.i(TAG, confirm.toJSONObject().toString(4));
                          Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
                          /**
                           *  TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
                           * or consent completion.
                           * See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                           * for more details.
                           *
                           * For sample mobile backend interactions, see
                           * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
                           */
                          Toast.makeText(
                                  getApplicationContext(),
                                  "PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG)
                                  .show();
  
                      } catch (JSONException e) {
                          Log.e(TAG, "an extremely unlikely failure occurred: ", e);
                      }
                  }
              } else if (resultCode == Activity.RESULT_CANCELED) {
                  Log.i(TAG, "The user canceled.");
              } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                  Log.i(
                          TAG,
                          "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
              }
          } else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
              if (resultCode == Activity.RESULT_OK) {
                  PayPalAuthorization auth =
                          data.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
                  if (auth != null) {
                      try {
                          Log.i("FuturePaymentExample", auth.toJSONObject().toString(4));
  
                          String authorization_code = auth.getAuthorizationCode();
                          Log.i("FuturePaymentExample", authorization_code);
  
                          sendAuthorizationToServer(auth);
                          Toast.makeText(
                                  getApplicationContext(),
                                  "Future Payment code received from PayPal", Toast.LENGTH_LONG)
                                  .show();
  
                      } catch (JSONException e) {
                          Log.e("FuturePaymentExample", "an extremely unlikely failure occurred: ", e);
                      }
                  }
              } else if (resultCode == Activity.RESULT_CANCELED) {
                  Log.i("FuturePaymentExample", "The user canceled.");
              } else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
                  Log.i(
                          "FuturePaymentExample",
                          "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
              }
          }
      }
  
      private void sendAuthorizationToServer(PayPalAuthorization authorization) {
  
          /**
           * TODO: Send the authorization response to your server, where it can
           * exchange the authorization code for OAuth access and refresh tokens.
           *
           * Your server must then store these tokens, so that your server code
           * can execute payments for this user in the future.
           *
           * A more complete example that includes the required app-server to
           * PayPal-server integration is available from
           * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
           */
  
      }
  
      @Override
      public void onDestroy() {
          // Stop service when done
          stopService(new Intent(this, PayPalService.class));
          super.onDestroy();
      }
  }
  </code></pre>
  
  <p>My XML file : </p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="net.sparkeek.test.cubydroid.app.PaypalActivity" &gt;
  
          &lt;Button
              android:id="@+id/buyItBtn"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:onClick="onBuyPressed"
              android:text="Buy a Thing" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And my manifest : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="net.sparkeek.test.cubydroid.app" &gt;
  
      &lt;!-- for most things, including card.io &amp; paypal --&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  
      &lt;!-- for card.io card scanning --&gt;
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
  
      &lt;uses-feature
          android:name="android.hardware.camera"
          android:required="false" /&gt;
      &lt;uses-feature
          android:name="android.hardware.camera.autofocus"
          android:required="false" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/logo_cuby"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name=".PaypalActivity"
              android:label="@string/title_activity_paypal" &gt;
          &lt;/activity&gt;
  
          &lt;service
              android:name="com.paypal.android.sdk.payments.PayPalService"
              android:exported="false" /&gt;
  
          &lt;activity android:name="com.paypal.android.sdk.payments.PaymentActivity" /&gt;
          &lt;activity android:name="com.paypal.android.sdk.payments.LoginActivity" /&gt;
          &lt;activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" /&gt;
          &lt;activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" /&gt;
          &lt;activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" /&gt;
          &lt;activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" /&gt;
          &lt;activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" /&gt;
          &lt;activity
              android:name="io.card.payment.CardIOActivity"
              android:configChanges="keyboardHidden|orientation" /&gt;
          &lt;activity android:name="io.card.payment.DataEntryActivity" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>