Smartling/android-repository

Crash when inflating a layout containing a WebView

dmapr opened this issue · 6 comments

dmapr commented

I've put together a project that shows the problem (the proxy layout inflater fails to inflate the WebView). It crashes when build with the Smartling SDK but works fine otherwise.

SmartlingMDN.zip

Hello, @dmapr. Thank you create the issue.
It's reproduced on my side as well.
Working on that.

BTW, could you please send me your stacktrace after crash so we can compare it with mine.
I have the following:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.onFinishInflate()' on a null object reference
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:826)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
     at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:116)
     at com.jivesoftware.rnd.smartlingmdn.databinding.ItemBinding.inflate(ItemBinding.java:127)
     at com.jivesoftware.rnd.smartlingmdn.databinding.ItemBinding.inflate(ItemBinding.java:124)
     at com.jivesoftware.rnd.smartlingmdn.MainActivity$TextRecyclerAdapter.onCreateViewHolder(MainActivity.java:61)
     at com.jivesoftware.rnd.smartlingmdn.MainActivity$TextRecyclerAdapter.onCreateViewHolder(MainActivity.java:56)
     at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6367)
     at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5555)
...

Thus, it seems the usage of databinding approach causes this issue. Anyway, I'm working on that. Just want to know how does your stacktrace look like. And also do you still have this issue if you remove these lines from your code:

 contents.add(new Content(Content.TextType.Rich,
                "<html><body>" +
                        "<h1>Movies</h1>" +
                        "<li>A Fistful of Dollars</li>" +
                        "<li>For a Few Dollars More</li>" +
                        "<li>The Good, the Bad and The Ugly</li>" +
                        "</ol>" +
                        "</body></html>"));

so that WebView doesn't appear on the screen.
Thanks.

Okay, now I see - Data Binding doesn't cause this issue itself. Smartling SDK is compatible with Data Binding approach.
The reason is WebView is presented in the layout file.

dmapr commented

@andriipanasiuk -- you're correct, the databinding has nothing to do with it. In the real app we have a crash with a dynamically created view that inflates its own layout (containing the WebView) from an XML file using LayoutInflater.from(context).inflate(R.layout...) call. Here's the relevant portion of the stack trace in that case:

03-24 11:12:42.610 E/AndroidRuntime(12103): android.view.InflateException: Binary XML file line #6: Attempt to invoke virtual method 'android.content.Context android.view.View.getContext()' on a null object reference
03-24 11:12:42.610 E/AndroidRuntime(12103): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.view.View.getContext()' on a null object reference
03-24 11:12:42.610 E/AndroidRuntime(12103): at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
03-24 11:12:42.610 E/AndroidRuntime(12103): at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
03-24 11:12:42.610 E/AndroidRuntime(12103): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-24 11:12:42.610 E/AndroidRuntime(12103): at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
03-24 11:12:42.610 E/AndroidRuntime(12103): at android.view.LayoutInflater.inflate(LayoutInflater.java:377)

I have also tried to use the fully qualified name of the WebView class (android.webkit.WebView) but that made no difference.

Please use the latest 2.3.2 version to fix this issue.

dmapr commented

Thank you! 2.3.2 works like a charm.