Error inflating WebView XML

前端 未结 7 1554
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 00:10

I found a crash report on Crashlytics in a Samsung SM G920F (Galaxy S6), version 5.1.1 (on all other devices I didn\'t retrieve same error).

java.lang.Runtim         


        
7条回答
  •  长发绾君心
    2021-01-04 00:45

    As @simon-ninon said, this is the way I implented in my app.

    In the onCreate of the activity that inflates Webview in the UI, you can have a try-catch to save yourself from the errors producing in the Crashlytics.

      /**
         * This element touches the UI elements
         * of the application and set them up.
         */
       try {
            setContentView(R.layout.activity_main);
            // ... further setup
        } catch (Exception ex) {
            transferToNoPackageFoundActivity(ex.getMessage());
        }
    
    
        private void transferToNoPackageFoundActivity(String errorMessage) {
            Intent intent = new Intent(this, NoPackageFoundActivity.class);
            intent.putExtra(Intent.EXTRA_INTENT, errorMessage);
            startActivity(intent);
            finish();
        }
    

    In the NoPackageFoundActivity, you can take the user to the Playstore for downloading the webview package.

        /**
     * This field is used for presenting the user
     * with an error image for no connectivity.
     */
    private lateinit var mErrorImage: ImageView
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_no_network)
        // get the intent for the error message, if any.
        val intent: Intent = intent
        if (intent.hasExtra(Intent.EXTRA_INTENT)) {
            println(intent.getStringExtra(Intent.EXTRA_INTENT))
        }
    
        mErrorImage = findViewById(R.id.error_image)
        mErrorImage.contentDescription = resources.getString(R.string.no_network_image_desc)
        Glide.with(this)
                .load(R.drawable.ic_no_web_view_illustration)
                .into(mErrorImage)
    
        val enableButton = findViewById

提交回复
热议问题