+
82
-

支付宝sdkdemo出现java.lang.NullPointerException

今天在支付宝官方下载了一个app支付的demo,结果一运行出现下面的错误

2019-08-15 18:28:58.114 32244-32244/com.alipay.sdk.pay.demo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.alipay.sdk.pay.demo, PID: 32244
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
        at android.view.View.performClick(View.java:6611)
        at android.view.View.performClickInternal(View.java:6588)
        at android.view.View.access$3100(View.java:788)
        at android.view.View$PerformClick.run(View.java:25973)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6921)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:937)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
        at android.view.View.performClick(View.java:6611) 
        at android.view.View.performClickInternal(View.java:6588) 
        at android.view.View.access$3100(View.java:788) 
        at android.view.View$PerformClick.run(View.java:25973) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6921) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:937) 
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
        at java.net.URLEncoder.encode(URLEncoder.java:204)
        at com.alipay.sdk.pay.demo.util.OrderInfoUtil2_0.getSign(OrderInfoUtil2_0.java:172)
        at com.alipay.sdk.pay.demo.PayDemoActivity.payV2(PayDemoActivity.java:166)
        at java.lang.reflect.Method.invoke(Native Method) 
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
        at android.view.View.performClick(View.java:6611) 
        at android.view.View.performClickInternal(View.java:6588) 
        at android.view.View.access$3100(View.java:788) 
        at android.view.View$PerformClick.run(View.java:25973) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6921) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:937) 

麻烦帮我看看,谢谢

高手回复

+
1
-
看看是不是秘钥的问题,最好使用支付宝官方的工具生成秘钥,并且复制,否则容易出问题
https://docs.open.alipay.com/291/106097
by bfwop
我知道答案,我要回答