更新时间:2023-09-25 16:13:46
目录名称应该是 assets 不是 android_assets
像这样: app-> New-> Folder-> Assets文件夹
现在将 .html 文件放在资产文件夹中。
就是这样。完成。
剩余的代码与您所做的一样。
WebView视图=新的WebView(this);
view.getSettings()。setJavaScriptEnabled(true);
view.loadUrl(file:///android_asset/hello.html);
setContentView(view);
I'm using Android Studio/Gradle.
app\src\main\android_asset folder has the file called chart.html..
I'm trying to load this file to my webview like this:
WebView view = new WebView(this);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl("file:///android_asset/chart.html");
setContentView(view);
But I always get the error: could not be loaded because ERR_FILE_NOT_FOUND.
What am I missing here?
The directory name should be assets not android_assets
Do like this:
As shown in the above pics just right click on your app->New->Folder->Assets Folder
Now put your .html file here in assets folder.
That's it. Done.
Remaining is same in code what you did.
WebView view = new WebView(this);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl("file:///android_asset/hello.html");
setContentView(view);