分支 IO 随机应用程序崩溃 - Kotlin

Posted

技术标签:

【中文标题】分支 IO 随机应用程序崩溃 - Kotlin【英文标题】:Branch IO random App crash - Kotlin 【发布时间】:2018-05-09 13:04:59 【问题描述】:

我正在为我的应用程序中的应用程序共享集成 Branch IO。我在 Branch 的帮助下使用以下代码实现了共享 URL 功能:

fun ShareApp()
    val appShare = BranchUniversalObject()
            .setCanonicalIdentifier("app-share")
            .setTitle(resources.getString(R.string.app_name))
            .setContentImageUrl(AppConstants.AppIconURL)
            .setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)

    val lp = LinkProperties()
            .setChannel("facebook")
            .setFeature("sharing")

    val ss = ShareSheetStyle(this, appName, Message)
            .setAsFullWidthStyle(true)
            .setSharingTitle("Share With")

    appShare.showShareSheet(this, lp, ss, object : Branch.BranchLinkShareListener 
        override fun onShareLinkDialogLaunched() 
        override fun onShareLinkDialogDismissed() 
        override fun onLinkShareResponse(sharedLink: String, sharedChannel: String, error: BranchError) 
        override fun onChannelSelected(channelName: String) 
    )

每当我点击任何频道时说 Whatsapp,有时它会起作用并将我带到 whatsapp。但是很多时候频道没有被选中,它给了我下面的崩溃:

FATAL EXCEPTION: main
                                                              Process: com.eonian.reelo, PID: 10038
                                                              java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter error
                                                                  at com.eonian.reelo.ui.profile.profileSettings.ProfileSettingsActivity$ShareApp$1.onLinkShareResponse(ProfileSettingsActivity.kt:0)
                                                                  at io.branch.indexing.BranchUniversalObject$LinkShareListenerWrapper.onLinkShareResponse(BranchUniversalObject.java:980)
                                                                  at io.branch.referral.ShareLinkManager.shareWithClient(ShareLinkManager.java:309)
                                                                  at io.branch.referral.ShareLinkManager.access$700(ShareLinkManager.java:32)
                                                                  at io.branch.referral.ShareLinkManager$3.onLinkCreate(ShareLinkManager.java:282)
                                                                  at io.branch.referral.ServerRequestCreateUrl.onUrlAvailable(ServerRequestCreateUrl.java:142)
                                                                  at io.branch.referral.Branch.generateShortLinkInternal(Branch.java:2052)
                                                                  at io.branch.referral.BranchUrlBuilder.generateUrlInternal(BranchUrlBuilder.java:140)
                                                                  at io.branch.referral.BranchShortLinkBuilder.generateShortUrlInternal(BranchShortLinkBuilder.java:144)
                                                                  at io.branch.referral.ShareLinkManager.invokeSharingClient(ShareLinkManager.java:278)
                                                                  at io.branch.referral.ShareLinkManager.access$500(ShareLinkManager.java:32)
                                                                  at io.branch.referral.ShareLinkManager$1.onItemClick(ShareLinkManager.java:233)
                                                                  at android.widget.AdapterView.performItemClick(AdapterView.java:310)
                                                                  at android.widget.AbsListView.performItemClick(AbsListView.java:1155)
                                                                  at android.widget.AbsListView$PerformClick.run(AbsListView.java:3152)
                                                                  at android.widget.AbsListView.onTouchUp(AbsListView.java:4079)
                                                                  at android.widget.AbsListView.onTouchEvent(AbsListView.java:3838)
                                                                  at android.view.View.dispatchTouchEvent(View.java:9942)
                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666)
                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2344)
                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2672)
                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                  at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:411)
                                                                  at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1810)
                                                                  at android.app.Dialog.dispatchTouchEvent(Dialog.java:793)
                                                                  at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:373)
                                                                  at android.view.View.dispatchPointerEvent(View.java:10162)
                                                                  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4446)
                                                                  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4314)
                                                                  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                                  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3914)
                                                                  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3880)
                                                                  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4007)
                                                                  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3888)
                                                                  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4064)
                                                                  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                                  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3914)
                                                                  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3880)
                                                                  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3888)
                                                                  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3861)
                                                                  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6257)
                                                                  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6196)
                                                                  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6157)
                                                                  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6360)

大多数情况下,它最终会因未选择频道名称而崩溃。执行中有什么问题吗?

谢谢

【问题讨论】:

【参考方案1】:

为避免崩溃,请使用此签名:

override fun onLinkShareResponse(
    sharedLink: String?, 
    sharedChannel: String?, 
    error: BranchError?)

然后您可以检查什么是 null 而不是获取低级异常。

我在 Branch 的网站上看到了代码,Kotlin 示例看起来很糟糕。我认为error 始终为非空是没有意义的,即使没有错误也是如此。 sharedChannel 在出错的情况下可能为空。

【讨论】:

来自分支机构的亚伦。 @Siraj,你能试试这个吗?如果这可以处理这种情况,我们当然可以更新文档以确保它适用于 Kotlin。 如果您不介意,您还应该从 Kotlin 示例中删除 new 关键字。它在 Kotlin 中不存在。

以上是关于分支 IO 随机应用程序崩溃 - Kotlin的主要内容,如果未能解决你的问题,请参考以下文章

使用带有 Kotlin 的 CameraKit 时应用程序崩溃

设置 MinifyEnabled 后应用程序崩溃并出现未知错误 - Kotlin

使用 kotlin-coroutine 时 OkHttp 调度程序崩溃

应用程序在 java.net.SocketTimeoutException 上崩溃:超时(Kotlin、Retrofit)

应用程序在 recyclerview 滚动 android kotlin 时崩溃

Kotlin / Android Studio - 当电子邮件地址格式错误时,应用程序在注册时崩溃[重复]