繁体   English   中英

应用内购买成功后出现奇怪的空指针异常(Android)

[英]Strange null pointer exception after in-app purchase successful (Android)

我已经使用应用内结算(IAB)编写了一个应用。 除了一件事,一切似乎都正常。 如果我促成购买,则显示Google Play IAB购买,并且我购买了商品,然后出现“购买完成”窗口,然后消失。 但是,我的主应用程序似乎没有开始重新设置动画,几秒钟后,该应用程序崩溃了。 我的logcat输出显示它们是空指针异常(与我自己的编码有关-与Android无关)

        try
        {
            Bundle buyIntentBundle = mService.getBuyIntent(3, mActivity.getPackageName(), (String)args[1], "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");

            if(buyIntentBundle.getInt("RESPONSE_CODE") == BILLING_RESPONSE_RESULT_OK)
            {
                PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

                try
                {
                    mActivity.startIntentSenderForResult(pendingIntent.getIntentSender(),
                               1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
                               Integer.valueOf(0));
                }
                catch (SendIntentException e)
                {
                    Log.v("MYINFO", "Error purchasing item.");
                    e.printStackTrace();
                }
            }
            else
            {
                Log.v("MYINFO", "Error purchasing item.");

                showResponse(buyIntentBundle.getInt("RESPONSE_CODE"));
            }
        }
        catch (RemoteException e1)
        {
            e1.printStackTrace();
        }

这段代码在我自己的AsyncTask购买类中,而mActivity是主要的Activity。 编码

  mActivity.startIntentSenderForResult(...)

在主Activity中调用'OnActivityResult(...)'正常,但随后发生崩溃。

有什么想法我可能做错了吗?

谢谢。

我的logcat输出它:

V/MediaPlayer[Native](12951): start
E/MediaPlayer[Native](12951): start called in state 0
V/MediaPlayer[Native](12951): message received msg=100, ext1=-38, ext2=0
E/MediaPlayer[Native](12951): error (-38, 0)
D/MediaPlayer[Native](12951): calling notify_player_state: 0
V/MediaPlayer[Native](12951): callback application
V/MediaPlayer[Native](12951): back from callback
D/MediaPlayer[JAVA](12951): broadcasting MEDIA_CHANGE_PLAYER_STATE(with context) : 0x0
E/MediaPlayer[Native](12951): invoke failed: wrong state 0
D/MediaPlayer[JAVA](12951): broadcasting MEDIA_CHANGE_PLAYER_STATE(with context) : state = 0
V/MediaPlayer[Native](12951): MediaPlayer::setVolume(0.750000, 0.750000)
E/MediaPlayer[JAVA](12951): Error (-38,0)
V/MediaPlayerService(  301): [669] setVolume(0.750000, 0.750000)
V/AudioSink(  301): setVolume(0.750000, 0.750000)
W/dalvikvm(12951): threadid=33: thread exiting with uncaught exception (group=0x41b5ee48)
E/AndroidRuntime(12951): FATAL EXCEPTION: GLThread 22274
E/AndroidRuntime(12951): Process: com.mystuff.grame, PID: 12951
E/AndroidRuntime(12951): java.lang.NullPointerException
E/AndroidRuntime(12951):    at com.mystuff.grame.core.SpriteBatch.add(SpriteBatch.java:50)
E/AndroidRuntime(12951):    at com.mystuff.grame.core.Level.draw(Level.java:360)
E/AndroidRuntime(12951):    at com.mystuff.grame.core.Grame.drawGame(Grame.java:245)
E/AndroidRuntime(12951):    at com.mystuff.grame.core.Grame.onDrawFrame(Grame.java:178)
E/AndroidRuntime(12951):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
E/AndroidRuntime(12951):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
W/ActivityManager(  972):   Force finishing activity com.mystuff.grame/.MainActivity
D/ActivityManager(  972): setFocusedStack: mFocusedStack=ActivityStack{439390b8 stackId=1, 21 tasks}
V/ActivityManager(  972): Moving to PAUSING: ActivityRecord{43d96740 u0 com.mystuff.grame/.MainActivity t421 f}
V/MediaPlayer[Native](12951): stop
E/MediaPlayer[Native](12951): stop called in state 0
V/MediaPlayer[Native](12951): message received msg=100, ext1=-38, ext2=0
E/MediaPlayer[Native](12951): error (-38, 0)
D/MediaPlayer[Native](12951): calling notify_player_state: 0
V/MediaPlayer[Native](12951): callback application
V/MediaPlayer[Native](12951): back from callback
V/ActivityManager(  972): Moving to PAUSED: ActivityRecord{43d96740 u0 com.mystuff.grame/.MainActivity t421 f} (pause complete)
V/ActivityManager(  972): Moving to STOPPING: ActivityRecord{43d96740 u0 com.mystuff.grame/.MainActivity t421 f} (finish requested)
I/ActivityManager(  972): resumeTopActivitiesLocked(): target Stack:ActivityStack{439390b8 stackId=1, 21 tasks}
D/ActivityManager(  972): resumeTopActivityLocked: Launching home next
V/ActivityManager(  972): moveHomeStack:

它必须与应用程序内购买有关,因为在应用程序内购买完成之前它不会发生……似乎应用程序内购买流程导致我的某些变量变为空。

你可能是对的。 打开IAP对话框后,我认为onPause已触发。 如果触发了onPause,则意味着很多变量都设置为null并像MediaPlayer一样关闭。

或者,当IAP对话框出现时,MediaPlayer(我认为是原因)被设置为强制暂停。 您可以尝试做的是在初始化购买流程时(或在按下触发它的按钮时)暂停MediaPLayer,并在完成后重新初始化

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM