2
回答
移动支付接口SDK2.0 调用pay()接口时直接崩溃,其他接口都没问题
华为云数据库免费试用   

已经按照开发文档导入相应的库了,

 

//这里调用支付类函数
	System.out.println("支付宝支付!");
	// 获取订单信息
	OrderNetity orderInfo = (OrderNetity) msg.getData().getSerializable("orderInfo");				
	PayDemoActivity pay = new PayDemoActivity();
	pay.valuation(orderInfo.getCommodity(),orderInfo.getCommodityDescribe(),orderInfo.getPrice(),orderInfo.getPartner(),orderInfo.getSeller(),orderInfo.getRsaPrivate(),orderInfo.getRsaPublic());
	pay.pay();
	break;
//这是支付函数
public void pay() {
// 订单
String orderInfo = getOrderInfo("测试的商品", "该测试商品的详细描述", "0.01");

     // 对订单做RSA 签名
     String sign = sign(orderInfo);
     try {
      // 仅需对sign 做URL编码
			sign = URLEncoder.encode(sign, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		// 完整的符合支付宝参数规范的订单信息
		final String payInfo = orderInfo + "&sign=\"" + sign + "\"&"
				+ getSignType();

		Runnable payRunnable = new Runnable() {

			@Override
			public void run() {
				// 构造PayTask 对象
				PayTask alipay = new PayTask(PayDemoActivity.this);
                                System.out.println("下面就会报错了!!!!");
// 调用支付接口,获取支付结果
				String result = alipay.pay(payInfo);

				Message msg = new Message();
				msg.what = SDK_PAY_FLAG;
				msg.obj = result;
				mHandler.sendMessage(msg);
			}
		};

		// 必须异步调用
		Thread payThread = new Thread(payRunnable);
		payThread.start();
	}

下面是报的错误

03-11 13:09:51.976: I/System.out(27710): 下面就回报错了!!!!
03-11 13:09:51.977: W/dalvikvm(27710): threadid=16: thread exiting with uncaught exception (group=0x4174cba8)
03-11 13:09:51.978: E/AndroidRuntime(27710): FATAL EXCEPTION: Thread-9351
03-11 13:09:51.978: E/AndroidRuntime(27710): Process: com.dishan.jzszp, PID: 27710
03-11 13:09:51.978: E/AndroidRuntime(27710): java.lang.NullPointerException
03-11 13:09:51.978: E/AndroidRuntime(27710):  at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
03-11 13:09:51.978: E/AndroidRuntime(27710):  at com.alipay.sdk.sys.GlobalContext.a(SourceFile:47)
03-11 13:09:51.978: E/AndroidRuntime(27710):  at com.alipay.sdk.app.PayTask.pay(SourceFile:72)
03-11 13:09:51.978: E/AndroidRuntime(27710):  at com.alipay.sdk.pay.demo.PayDemoActivity$2.run(PayDemoActivity.java:137)
03-11 13:09:51.978: E/AndroidRuntime(27710):  at java.lang.Thread.run(Thread.java:841)




举报
新来了的
发帖于4年前 2回/2K+阅
顶部