Android应用内评论弹窗导致应用崩溃。

huangapple go评论77阅读模式
英文:

Android In-app Review pop-up crashes the app

问题

尝试在Android应用中实现内置评论功能时,我在运行测试FakeReviewManager时没有问题,如下所述,但是当我将其替换为真实的管理器时,窗口弹出时会导致崩溃。这是我现在的代码:

ReviewManager manager;
ReviewInfo reviewInfo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //manager = new FakeReviewManager(context);
    manager = ReviewManagerFactory.create(this);
    Task<ReviewInfo> request = manager.requestReviewFlow();
    request.addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            Log.d("myTag","Review can be requested");
            reviewInfo = task.getResult(); // 注意这里修复了ReviewInfo的赋值
        } else {
            // 发生了一些问题,不管结果如何都继续。
        }
    });
}

public void ProgressManagement() {

     Task<Void> flow = manager.launchReviewFlow(MainActivity.this, reviewInfo);
     flow.addOnCompleteListener(task -> {
     Log.d("myTag","Review process completed");
     });
}

这是我收到的错误代码:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android, PID: 16579
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.PendingIntent com.google.android.play.core.review.ReviewInfo.a()' on a null object reference
    at com.google.android.play.core.review.c.launchReviewFlow(Unknown Source:7)
    at com.android.MainActivity.ProgressManagement(MainActivity.java:280)
    at com.android.MainActivity$4.onClick(MainActivity.java:209)
    at android.view.View.performClick(View.java:6897)
    at android.view.View$PerformClick.run(View.java:26104)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

请注意,我在 onCreate 方法中修复了 reviewInfo 的赋值,以便在 ProgressManagement 方法中使用它。这应该解决 NullPointerException 的问题。

英文:

Trying to implement the in-app Review for Android I had no problem running the test FakeReviewManager as commented below, but when swapping it out with the real manager I get a crash as the window should pop up. This is the code I have:

ReviewManager manager;
ReviewInfo reviewInfo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //manager = new FakeReviewManager(context);
    manager = ReviewManagerFactory.create(this);
    Task&lt;ReviewInfo&gt; request = manager.requestReviewFlow();
    request.addOnCompleteListener(task -&gt; {
        if (task.isSuccessful()) {
            Log.d(&quot;myTag&quot;,&quot;Review can be requested&quot;);
            ReviewInfo reviewInfo = task.getResult();
        } else {
            // There was some problem, continue regardless of the result.
        }
    });
}

public void ProgressManagement() {

     Task&lt;Void&gt; flow = manager.launchReviewFlow(MainActivity.this, reviewInfo);
     flow.addOnCompleteListener(task -&gt; {
     Log.d(&quot;myTag&quot;,&quot;Review process completed&quot;);
     });
}

This is the error code I get:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android, PID: 16579
java.lang.NullPointerException: Attempt to invoke virtual method &#39;android.app.PendingIntent com.google.android.play.core.review.ReviewInfo.a()&#39; on a null object reference
    at com.google.android.play.core.review.c.launchReviewFlow(Unknown Source:7)
    at com.android.MainActivity.ProgressManagement(MainActivity.java:280)
    at com.android.MainActivity$4.onClick(MainActivity.java:209)
    at android.view.View.performClick(View.java:6897)
    at android.view.View$PerformClick.run(View.java:26104)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

答案1

得分: 0

试试这个:

在下面添加以下内容:

private ReviewInfo reviewInfo;

在下面这行代码之后:

ReviewManager manager;

然后将这段代码修改为:

if (task.isSuccessful()) {
    Log.d("myTag", "可以请求评论");
    reviewInfo = task.getResult();
}
英文:

Try this:

add the following

private ReviewInfo reviewInfo;

below

ReviewManager manager;

and then change this:

if (task.isSuccessful()) {
        Log.d(&quot;myTag&quot;,&quot;Review can be requested&quot;);
        ReviewInfo reviewInfo = task.getResult();
    }

to this:

if (task.isSuccessful()) {
        Log.d(&quot;myTag&quot;,&quot;Review can be requested&quot;);
        reviewInfo = task.getResult();
    }

答案2

得分: 0

看起来你没有初始化ui。setContentView()没有出现。

英文:

Looks like you didn't initialize ui. setContentView() is absent.

huangapple
  • 本文由 发表于 2020年8月24日 06:22:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63552588.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定