Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在自定义View里使用,布局不能预览 #148

Open
SelectSex opened this issue Nov 11, 2021 · 3 comments
Open

在自定义View里使用,布局不能预览 #148

SelectSex opened this issue Nov 11, 2021 · 3 comments

Comments

@SelectSex
Copy link

描述 Bug

自定义view中调用了LiveEventBus.get方法,无法预览,

  • 库 的版本:1.8.0
  • 出现 Bug 的设备型号: studio直接预览报错
  • 设备的 Android 版本:项目编译sdk api 30

相关代码

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        LiveEventBus.get<Int>(EventKeys.Bet_Click_Parlay_Refresh).observeForever(updataUi)
        GlobalRequest.getMemberBalance.observeForever(getMemberBalance)
    }

异常堆栈

java.lang.NullPointerException   at java.lang.reflect.Method.invoke(Method.java:559)
   at com.jeremyliao.liveeventbus.utils.AppUtils.getApplicationByReflect(AppUtils.java:98)
   at com.jeremyliao.liveeventbus.utils.AppUtils.getApp(AppUtils.java:88)
   at com.jeremyliao.liveeventbus.core.LiveEventBusCore.registerReceiver(LiveEventBusCore.java:123)
   at com.jeremyliao.liveeventbus.core.LiveEventBusCore.<init>(LiveEventBusCore.java:83)
   at com.jeremyliao.liveeventbus.core.LiveEventBusCore.<init>(LiveEventBusCore.java:38)
   at com.jeremyliao.liveeventbus.core.LiveEventBusCore$SingletonHolder.<clinit>(LiveEventBusCore.java:44)
   at com.jeremyliao.liveeventbus.core.LiveEventBusCore.get(LiveEventBusCore.java:48)
   at com.jeremyliao.liveeventbus.LiveEventBus.get(LiveEventBus.java:35)
   at com.jeremyliao.liveeventbus.LiveEventBus.get(LiveEventBus.java:46)
   at com.android.orange_android.widget.BetTopTitleView.onAttachedToWindow(BetTopTitleView.kt:159)

截图

image
简单报错
image
具体详细错误
image

分析

在此处调用invoke,会在自定义view中预览时抛出Null异常。

image

invoke 方法会报错

image

报错后未try catch

image

@SelectSex
Copy link
Author

live_event_bug_x1.8.0.zip
将我正在用的1.8.0都aar反编译修改了 getApplicationByReflect方法,引入项目,预览终于正常了
我修改的代码并不会对app运行时造成错误,只是修改了npe异常的使用,好让 预览编译顺利运行下去

@Lieeber
Copy link

Lieeber commented Jan 4, 2022

想预览用isInEditMode就行了。

@SelectSex
Copy link
Author

SelectSex commented Apr 19, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants