2013-03-20 125 views
2
FATAL EXCEPTION: Thread-5195 
java.lang.NullPointerException: src == null 
    at java.lang.System.arraycopy(Native Method) 
    at com.paypal.android.a.g.a(Unknown Source) 
    at com.paypal.android.a.h.c(Unknown Source) 
    at com.paypal.android.MEP.PayPal.setLanguage(Unknown Source) 
    at com.paypal.android.MEP.PayPal.initWithAppID(Unknown Source) 
    at com.lonfun.pets.UnityPayMenuActivity.initLibrary(UnityPayMenuActivity.java:256) 
    at com.lonfun.pets.UnityPayMenuActivity.access$2(UnityPayMenuActivity.java:249) 
    at com.lonfun.pets.UnityPayMenuActivity$2$1.run(UnityPayMenuActivity.java:175) 

我只是用android打開貝寶,一切都OK,但如果我從統一調用,這是發生! 這是我的java代碼:PayPal.initWithAppID()崩潰與空指針異常

package com.paypal.androidpets;

import android.content.Context; 
import android.os.Handler; 

import com.lonfun.pets.UnityPayMenuActivity; 
import com.paypal.android.MEP.PayPal; 
import com.paypal.android.MEP.PayPalActivity; 

public class PaypalTool { 
    Context context; 
    PayPal pp; 
    private static final int server = PayPal.ENV_SANDBOX; 
    // The ID of your application that you received from PayPal 
    private static final String appID = "APP-80W284485P519543T"; 

    public PaypalTool(Context context) { 
     this.context=context; 
    } 

    public void initLibrary(final Handler handler) 
    { 
     new Thread() { 
      public void run() { 
       PayPalActivity._paypal = null; 
       pp = PayPal.getInstance(); 
       // If the library is already initialized, then we don't need to initialize it again. 
       if(pp == null) { 
//     pp = PayPal.initWithAppID(context, "", PayPal.ENV_NONE); 
        pp = PayPal.initWithAppID(context, appID, server); 

        pp.setShippingEnabled(false); 
       } 

       if (PayPal.getInstance().isLibraryInitialized()) { 
        handler.sendEmptyMessage(0); 
       } 
       else { 
        handler.sendEmptyMessage(1); 
       } 
      } 
     }.start(); 
    } 
} 

有人解決了這個問題,,請幫幫我,謝謝!

using UnityEngine; 
using System.Collections; 

public class PayMoneyHandler : MonoBehaviour 
{ 

    #if UNITY_ANDROID 
    static AndroidJavaClass payPluginClass; 
    static AndroidJavaClass unityPlayer; 
    static AndroidJavaObject currActivity; 
    #endif 

    public static void Pay(string productID) 
    { 
#if UNITY_ANDROID 
     AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
     AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); 
     jo.Call("StartActivity0", 
      "com.peten.tier2", 
      "EGAHCNJDEJBWBIBWEXIKDEGLJECOAD.Mac", 
      "Dog", 
      "AndDogCn", 
      "http://42.121.94.123/TradeWeb/AlipayTrade.aspx", 
      "http://58.246.188.238/TradeWeb/PaypalTrade.aspx" 
      ); 
#endif 
    } 

} 
using UnityEngine; 
using System.Collections; 

public class TestForPaypal : MonoBehaviour { 

    // Use this for initialization 
    void Start() { 

    } 

    // Update is called once per frame 
    void Update() { 

    } 

    public void OnClick(){ 
     Debug.Log("Test For Paypal!"); 
     PayMoneyHandler.Pay("test1"); 
    } 
} 

public void StartActivity0(final String name,final String PlayerName,final String GameID,final String ZoneID,final String payUrl,final String paypalUrl) 
    {  
     this.runOnUiThread(new Runnable() { 

      @Override 
      public void run() { 
       Log.i("Order", "name:"+name+"PlayerName:"+PlayerName+"GameID:"+GameID+"ZoneID:"+ZoneID+"payUrl:"+payUrl+"paypalUrl:"+paypalUrl); 
       Intent payintent=new Intent(mContext,UnityPayMenuActivity.class); 
       payintent.putExtra("name",name); 
       payintent.putExtra("PlayerName",PlayerName); 
       payintent.putExtra("GameID",GameID); 
       payintent.putExtra("ZoneID",ZoneID); 
       payintent.putExtra("payUrl",payUrl); 
       payintent.putExtra("paypalUrl",paypalUrl); 
       Unity3DMainActiviy.this.startActivity(payintent); 
      } 
     }); 
    } 
+0

請問您可以上傳完整的代碼片段嗎? – Raynold 2013-03-20 09:56:16

+0

private static final int server = PayPal。ENV_SANDBOX; \t //您從PayPal收到的應用程序ID private static final String appID =「APP-80W284485P519543T」;我之前定義過, – 2013-03-20 11:42:58

+0

我添加完整的代碼,如果我編寫一個使用paypal的android應用程序,它運行良好,但從Unity3D調用PaypalTool,然後崩潰allways, – 2013-03-20 11:53:51

回答

0

我想你沒有輸入appID和服務器的詳細信息。 下面是我已經實現的工作代碼,它適用於我。 我有實現它擴展了可運行

Check_out.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      if (_paypalLibraryInit) { 
     showPayPalButton(); 
     //Toast.makeText(Android_PP_Test1Activity.this, captions[position], Toast.LENGTH_SHORT).show(); 

     } 
      else { 
      // Display a progress dialog to the user and start checking for when 
     // the initialization is completed 


      Thread initThread = new Thread(initLibraryRunnable); 
      initThread.start(); 

      _progressDialog = new ProgressDialog(Recharge.this); 
     _progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     _progressDialog.setMessage("Loading PayPal Payment Library"); 
     _progressDialog.setCancelable(false); 
     _progressDialog.show(); 
     _progressDialogRunning = true; 
     Thread newThread = new Thread(checkforPayPalInitRunnable); 

     newThread.start(); 
     //Toast.makeText(Android_PP_Test1Activity.this, "Picasso Paintings", Toast.LENGTH_SHORT).show(); 


     } 
    } 


}); 

該按鈕來調用此方法可運行

//This lets us run the initLibrary function 
    final Runnable initLibraryRunnable = new Runnable() { 
     public void run() { 
      initLibrary(); 
     } 
    }; 

按鈕點擊付費,這方法負責啓動initLibrary。

/** init method **/ 
public void initLibrary() { 
    PayPal pp = PayPal.getInstance(); 
    if (pp == null) { 
     // This is the main initialization call that takes in your Context, 
     // the Application ID, and the server you would like to connect to. 
     pp=PayPal.initWithAppID(this,"APP80W284485P519543T",PayPal.ENV_SANDBOX); 

     // -- These are required settings. 
     pp.setLanguage("en_US"); // Sets the language for the library. 
     // -- 

     // -- These are a few of the optional settings. 
     // Sets the fees payer. If there are fees for the transaction, this 
     // person will pay for them. Possible values are FEEPAYER_SENDER, 
     // FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and 
     // FEEPAYER_SECONDARYONLY. 
     pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER); 
     // Set to true if the transaction will require shipping. 
     pp.setShippingEnabled(true); 
     // Dynamic Amount Calculation allows you to set tax and shipping 
     // amounts based on the user's shipping address. Shipping must be 
     // enabled for Dynamic Amount Calculation. This also requires you to 
     // create a class that implements PaymentAdjuster and Serializable. 
     pp.setDynamicAmountCalculationEnabled(false); 
     // -- 


    } 
} 

希望它可以幫助...

+0

如果您需要更多的幫助,貝寶還提供此文檔 [Android中的Paypal MPL集成](https://www.x.com/developers/paypal/how-to-guides/how-accept-payments-android -app-using-mpl) – 2013-03-20 11:28:16

+0

private static final int server = PayPal.ENV_SANDBOX; \t //您從PayPal收到的應用程序ID \t private static final String appID =「APP-80W284485P519543T」;我之前定義的 – 2013-03-20 11:44:39

+0

檢查我編輯的答案..希望這會有所幫助... – 2013-03-20 12:06:16

0

問題是,當統一生成APK文件。我比較了一個apk,我把miself和PayPal整合在一起,只用eclipse和其他Unity編譯來編譯。假設我只用eclipse製作的apk文件名爲「PayPalOnlyEclipse.apk」,而用統一的「PayPalWithUnity.apk」製作的apk文件名爲「PayPalOnlyEclipse.apk」。 y將它們重命名爲「PayPalOnlyEclipse.zip」和「PayPalWithUnity.zip」,然後使用WinRar打開它們進行比較。

我發現PayPalOnlyEclipse有一個PayPalWithUnity沒有的文件夾,文件夾是「com \ paypal \ android \ utils \ data」。所以我解壓縮該文件夾,然後將其添加到PayPalWithUnity。然後清除META-INF文件夾(簽名),然後關閉「PayPalWithUnity.zip」並重命名爲之前的版本(「PayPalWithUnity.apk」)。

然後我用命令簽署apk文件: 的jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore my.keystore PayPalWithUnity.apk用戶

最後我用的zipalign命令: 的zipalign -v 4 PayPalWithUnity.apk PayPalWithUnity2.apk

該命令生成PayPalWithUnity2.apk,這是你必須安裝在手機中的apk文件。

希望它有幫助,對不起我的英語。

0

檢查您是否在清單文件中包含了PaypalActivity。就像這樣:

<activity android:name="com.paypal.android.MEP.PayPalActivity" 
     android:configChanges="keyboardHidden|orientation" /> 

如果你有它,它不工作還沒有,包括構建路徑(屬性>> Java的打造專業化路徑>>圖書館>>添加JAR文件),並添加它的「命令和庫導出「選項卡(屬性>> Java Buid路徑>>訂單和導出)。