FontsManager.setFont throws exception
I get the following crash when application process is killed by the system and the app is resumed from the background -
android.view.InflateException: Binary XML file line #100 in
...:layout/chat_detail_fragment: Binary XML file line #100 in
...:layout/chat_detail_fragment: Error inflating class com.getstream.sdk.chat.view.MessageInputView
Caused by: android.view.InflateException: Binary XML file line #100 in com.s...:layout/chat_detail_fragment: Error inflating class com.getstream.sdk.chat.view.MessageInputView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:854)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
...
2019-12-12 00:39:42.290 11015-11015/E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.getstream.sdk.chat.style.FontsManager.setFont(com.getstream.sdk.chat.style.TextStyle, android.widget.TextView)' on a null object reference
at com.getstream.sdk.chat.style.TextStyle.apply(TextStyle.java:39)
at com.getstream.sdk.chat.view.MessageInputView.applyStyle(MessageInputView.java:156)
at com.getstream.sdk.chat.view.MessageInputView.<init>(MessageInputView.java:113)
... 48 more
ChatDetailFragment
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
chatDetailBinding = DataBindingUtil.inflate(inflater, R.layout.chat_detail_fragment, container, false)
chatDetailBinding.lifecycleOwner = this
}
Crash starts from trying to inflate the view which contains the MessageInputView
To reproduce;
- Open a conversation detail fragment
- Move app to background
- Click on the red stop button on logcat to simulate Application process being killed by the OS
- Open the app again after that Result; App crashes with the above error while inflating the MessageInputView
@Chikrix could you provide more information? Logs and sample of code would be nice.
I've updated it @andriizhumela
@Chikrix and where you init StreamChat? Could you explain how you build your architecture? did you check the sample?
@andriizhumela I have a single activity architecture and always initialized Stream in my activity's onCreate. But on Application death, the stream chat isn't initialized anymore, I have handled this, but this is generally my biggest discomfort with the library, the god singleton streamclient which isn't in anyway lifecycle aware, makes it very hard to be flexible and adds restrictions. It's not a good approach imho. Having such kinds of classes in a view would always lead to a crash like like this. I'm not initialising stream client in my Application class as I save my keys in my server
@samiuelson is working on a new version of the sample app. Also @JcMinarro
This problem is going to be completely resolved on the upcoming v4 release, I am going to close this issue. You can already try the beta version of v4 or otherwise subscribe to this issue #554 to get notified when v4 is released as stable.