我有一个刚刚在市场上推出的应用程序,它采用应用程序内购买,它是由我几乎不理解的其他人的示例代码拼凑而成的。该代码似乎在大多数情况下都可以正常工作,但我有一台设备每次都会崩溃。它似乎在 gen 目录中的一些“生成的 java 文件”中崩溃,我在崩溃之前跟踪了最后几个步骤,如下所示:
protected static boolean isBillingSupported()
{
if (amIDead())
{
return false;
}
Bundle request = makeRequestBundle("CHECK_BILLING_SUPPORTED");
if (mService != null && request != null)
{
try
{
Bundle response = mService.sendBillingRequest(request);
然后我进入这个方法并执行以下行......(见评论)
public android.os.Bundle sendBillingRequest(android.os.Bundle bundle) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
android.os.Bundle _result;
try
{
_data.writeInterfaceToken(DESCRIPTOR); // DESCRIPTOR was "com.android.vending.billing.IMarketBillingService"
if ((bundle!=null))
{
_data.writeInt(1); // GOT HERE OK
bundle.writeToParcel(_data, 0);
}
else
{
_data.writeInt(0);
}
mRemote.transact(Stub.TRANSACTION_sendBillingRequest, _data, _reply, 0); // GOT HERE OK
_reply.readException(); // GOT HERE OK ... BUT THEN JUMPS TO XXXX
if ((0!=_reply.readInt())) // WE NEVER REACH THIS LINE!
{
_result = android.os.Bundle.CREATOR.createFromParcel(_reply);
}
else
{
_result = null;
}
}
finally // XXXX
{
_reply.recycle(); // THIS GETS EXECUTED
_data.recycle(); // THIS GETS EXECUTED
}
return _result; // WE REACH HERE, BUT THAT'S THE LAST LINE I SEE BEFORE THE EXCEPTION APPEARS IN THE LOG OUTPUT
}
日志文件显示以下内容:
01-10 22:54:00.730: W/dalvikvm(1292): threadid=1: thread exiting with uncaught exception (group=0x401cb760)
01-10 22:54:00.740: E/AndroidRuntime(1292): FATAL EXCEPTION: main
01-10 22:54:00.740: E/AndroidRuntime(1292): java.lang.NullPointerException
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.os.Parcel.readException(Parcel.java:1327)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.os.Parcel.readException(Parcel.java:1275)
01-10 22:54:00.740: E/AndroidRuntime(1292): at com.android.vending.billing.IMarketBillingService$Stub$Proxy.sendBillingRequest(IMarketBillingService.java:100)
01-10 22:54:00.740: E/AndroidRuntime(1292): at com.mycompany.mygame.BillingHelper.isBillingSupported(BillingHelper.java:64)
01-10 22:54:00.740: E/AndroidRuntime(1292): at com.mycompany.mygame.Shop.onClick(Shop.java:174)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.view.View.performClick(View.java:3122)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.view.View$PerformClick.run(View.java:11942)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.os.Handler.handleCallback(Handler.java:587)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.os.Handler.dispatchMessage(Handler.java:92)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.os.Looper.loop(Looper.java:132)
01-10 22:54:00.740: E/AndroidRuntime(1292): at android.app.ActivityThread.main(ActivityThread.java:4028)
01-10 22:54:00.740: E/AndroidRuntime(1292): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 22:54:00.740: E/AndroidRuntime(1292): at java.lang.reflect.Method.invoke(Method.java:491)
01-10 22:54:00.740: E/AndroidRuntime(1292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
01-10 22:54:00.740: E/AndroidRuntime(1292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
01-10 22:54:00.740: E/AndroidRuntime(1292): at dalvik.system.NativeStart.main(Native Method)
01-10 22:54:02.770: I/dalvikvm(1292): threadid=4: reacting to signal 3
01-10 22:54:02.770: I/dalvikvm(1292): Wrote stack traces to '/data/anr/traces.txt'
我不确定从这里去哪里,因为我对发生的事情完全感到困惑。我对如何或为什么会“生成”此代码感到困惑……大概即使我在这里看到了一个错误,我也无法对其进行编辑!此代码是 Android 操作系统的一部分吗?也许真正的错误在传递的包中?...欢迎所有提示。