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)

私はアンドロイドを使ってペイパルを開くだけです。すべて問題ありませんが、ユニティから呼び出すと、これが起こります! これは私のJavaコードです:

パッケージ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);
            }
        });
    }
4

3 に答える 3

0

マニフェスト ファイルに PaypalActivity が含まれているかどうかを確認します。このような:

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

持っていてまだ動作しない場合は、ビルド パスにライブラリを含め ([プロパティ] > [Java ビルド パス] > [ライブラリ] > [JAR を追加])、[注文とエクスポート] タブ ([プロパティ] > [Java ビルド パス]) に追加します。 >>注文と輸出)。

于 2013-07-03T15:40:31.883 に答える
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);
        // -- 


    }
}

それが役に立てば幸い...

于 2013-03-20T11:16:52.903 に答える