简体   繁体   English

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

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

I've written an app with in app billing (IAB). 我已经使用应用内结算(IAB)编写了一个应用。 Everything seems to work fine, except one thing. 除了一件事,一切似乎都正常。 If I instigate a purchase, the Google Play IAB purchase appears and I purchase an item fine, then the Purchase Complete window appears, and then disappears fine. 如果我促成购买,则显示Google Play IAB购买,并且我购买了商品,然后出现“购买完成”窗口,然后消失。 However, my main app doesn't seem to start animating again and after a few seconds, the app crashes. 但是,我的主应用程序似乎没有开始重新设置动画,几秒钟后,该应用程序崩溃了。 My logcat output says their is a null pointer exception (related to my own coding - nothing Android specific) 我的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();
        }

This code is within my own AsyncTask purchasing class, and the mActivity is the main Activity. 这段代码在我自己的AsyncTask购买类中,而mActivity是主要的Activity。 The code 编码

  mActivity.startIntentSenderForResult(...)

calls the 'OnActivityResult(...)' fine in the main Activity, but then the crash occurs. 在主Activity中调用'OnActivityResult(...)'正常,但随后发生崩溃。

Any ideas what I might be doing wrong? 有什么想法我可能做错了吗?

Thank you. 谢谢。

My logcat output it: 我的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:

It must have something to do with the in-app purchasing as it doesn't happen until the in app purchase completes... it seems the in app purchase flow is causing some of my variables to become null. 它必须与应用程序内购买有关,因为在应用程序内购买完成之前它不会发生……似乎应用程序内购买流程导致我的某些变量变为空。

YOu are probably right. 你可能是对的。 When the IAP dialog is opened, I think onPause is triggered. 打开IAP对话框后,我认为onPause已触发。 If onPause is triggered that means a lot of variables is set to null and shut down like the MediaPlayer. 如果触发了onPause,则意味着很多变量都设置为null并像MediaPlayer一样关闭。

Alternativly, the MediaPlayer(which I think is the cause) is set to a forced pause when the IAP dialog shows up. 或者,当IAP对话框出现时,MediaPlayer(我认为是原因)被设置为强制暂停。 What you could try to do is pause the MediaPLayer when the purchase flow is initialized(or when a button is pressed that triggers it) and reininitialize when it is done 您可以尝试做的是在初始化购买流程时(或在按下触发它的按钮时)暂停MediaPLayer,并在完成后重新初始化

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

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