java - 无法为 WebView 创建图层,尺寸 640x7040 最大尺寸 8192 颜色类型 4 具有上下文 1

标签 java android webview samsung-mobile

我在 ScrollView 中使用 WebView,它在 Samsung SM-J610F 上给出了 IllegalStateException。它在我测试过此代码的其他设备上运行良好。

当我从 ScrollView 中取出 WebView 时,它工作正常。但问题是我在 WebView 下还有其他 View ,如果我不使用 ScrollView,用户将无法看到这些 View 。

Font Cache (CPU):
      Size: 103.02 kB 
      Glyph Count: 37 
    CPU Caches:
      Shadows: 4.22 KB (2 entries)
    GPU Caches:
      Other:
        Buffer Object: 63.00 KB (2 entries)
      Image:
        Texture: 1.81 MB (28 entries)
             Texture( 1):      168840 Byte (count:8)
             Texture( 2):       54288 Byte (count:1)
             Texture( 3):       44100 Byte (count:1)
             Texture( 4):       31684 Byte (count:6)
             Texture( 5):       29580 Byte (count:1)
             Texture( 6):       29568 Byte (count:1)
             Texture( 7):       29232 Byte (count:3)
             Texture( 8):       28896 Byte (count:1)
             Texture( 9):       28560 Byte (count:1)
             Texture(10):       11024 Byte (count:1)
             .......   
      Scratch:
        Texture: 512.00 KB (1 entry)
        RenderTarget: 1.46 MB (14 entries)
        Buffer Object: 96.03 KB (4 entries)
    Other Caches:
                             Current / Maximum
      VectorDrawableAtlas    0.00 kB /   0.00 KB (entries = 0)
      Layers Total           0.00 KB (numLayers = 0)
    Total GPU memory usage

JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethod called with pending exception java.lang.IllegalStateException: Unable to create layer for WebView, size 640x7040 max size 8192 color type 4 has context 1
......

最佳答案

将 webview 从 ScrollView 中移除并单独放置。此外,所有其他 View 都将它们添加到 ScrollView 中。这样您的 webview 也将稳定,用户将能够滚动并引用其他 View 。 此外,应正确声明和实现 webview:

 wv = (WebView) findViewById(R.id.web_view);
        wv.setInitialScale(1);      //webview page matches the screen size.
        wv.getSettings().setLoadWithOverviewMode(true);
        wv.getSettings().setUseWideViewPort(true);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);    //loads online website when no internet connection.
        wv.loadUrl("https://prajwalwaingankar.wixsite.com/nivala");

按照上面的代码,所有 View 都在 webview 之上,webview 使用方法覆盖了剩余屏幕尺寸的其余部分
.setInitialScale(1);

关于java - 无法为 WebView 创建图层,尺寸 640x7040 最大尺寸 8192 颜色类型 4 具有上下文 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56690236/

相关文章:

android - 禁用所有 MapView 手势并向 MapView 添加 OnClickListener

android - 从 Android 中的 WebView 问题制作位图

html - 如何在 html 内容之后放置 View

java - JFace Action 和 ImageDescriptor - 我想显示图像和文本

java - 这是装饰器模式还是策略模式,还是两者都不是?

java - 如何使用 Apache Common fileupload 将上传文件的路径设置为 "context path"?

javascript - 加载html后将js文件从assets加载到webview

java - 在 NetBeans 平台上,具有主要和次要首选项面板

Android 仅对 Edittext 禁用空间

java - 突然我的应用程序无法进行 HTTPS 查询