初始化贝宝只有一次

问题描述:

我已经设计了贝宝的功能在我的项目是这样的:初始化贝宝只有一次

public class MypaypalActivity extends Activity implements OnClickListener{ 

    /** Called when the activity is first created. */ 
    @Override 

public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     LinearLayout mLinLay= new LinearLayout(this); 

     setContentView(R.layout.main); 

     PayPal pp = PayPal.initWithAppID(this, "APP- 

80W284485P519543T",PayPal.ENV_SANDBOX); 


     LinearLayout layoutSimplePayment = new LinearLayout(this); 

     layoutSimplePayment.setLayoutParams(new LayoutParams(

       LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

     layoutSimplePayment.setOrientation(LinearLayout.VERTICAL); 

     CheckoutButton launchSimplePayment = pp.getCheckoutButton(this, 

       PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY); 

     launchSimplePayment.setOnClickListener(this); 

     layoutSimplePayment.addView(launchSimplePayment); 

     mLinLay.addView(layoutSimplePayment); 

     setContentView(mLinLay); 

    } 

这将非常正确工作只有一次。当我再次按下PayPal按钮时,此应用程序崩溃。 catlog中有一个错误是您初始化了两次PayPal,所以使用getInstance();初始化后。

我该怎么办?

嘿,这是我的问题的解决方案,我自己做了这个。

PayPal pp = PayPal.getInstance(); 
     if (pp == null) { 
      try { 
       pp = PayPal.initWithAppID(this, "", PayPal.ENV_NONE); 
      } catch (IllegalStateException e) { 
       throw new RuntimeException(e); 
      } 
      pp.setShippingEnabled(false); 
     } 

谢谢大家......

+0

谢谢达门德拉先生...... –