
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
今天学习WebView相关的知识,实践的时候一直报WebView空指针,最后排查发现是布局文件的问题。
原先的布局文件
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<WebView
ohos:id="$+id:webview"
ohos:height="match_parent"
ohos:width="match_parent"/>
</DirectionalLayout>
这里是按照Android习惯,直接写的WebView,而正确的应该是把WebView的全路径写出来才不会报空指针
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<ohos.agp.components.webengine.WebView
ohos:id="$+id:webview"
ohos:height="match_parent"
ohos:width="match_parent"/>
</DirectionalLayout>
具体原因有大佬知道吗?求指导