1. 程式人生 > >【未解決】java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitm

【未解決】java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitm

接應用寶sdk,在支付時

Bitmap bmp = BitmapFactory.decodeResource(mMainActivity.getResources(), R.drawable.sample_yuanbao);
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
              bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
               byte[] appResData = baos.toByteArray();
               String ysdkExt = "ysdkExt";
               YSDKApi.recharge(zoneId, saveValue,isCanChange,appResData,exts,new YSDKCallback(mMainActivity));

按demo填寫的程式碼  如果直接在eclipse中打包一個demo測試不會出問題,在unity中打包會報以下錯誤:

 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference