stream-chat-android icon indicating copy to clipboard operation
stream-chat-android copied to clipboard

FontsManager.setFont throws exception

Open Chikrix opened this issue 6 years ago • 6 comments

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 avatar Dec 11 '19 03:12 Chikrix

@Chikrix could you provide more information? Logs and sample of code would be nice.

andriizhumela avatar Dec 11 '19 14:12 andriizhumela

I've updated it @andriizhumela

Chikrix avatar Dec 12 '19 09:12 Chikrix

@Chikrix and where you init StreamChat? Could you explain how you build your architecture? did you check the sample?

andriizhumela avatar Dec 13 '19 12:12 andriizhumela

@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

Chikrix avatar Dec 17 '19 10:12 Chikrix

@samiuelson is working on a new version of the sample app. Also @JcMinarro

tschellenbach avatar May 16 '20 20:05 tschellenbach

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.

tbarbugli avatar Jul 03 '20 09:07 tbarbugli