[英]Android Studio (Web page help) net : ERR_FILE_NOT_FOUND
Im trying to implement my web app / page inside android studio from my local files, ive followed the official documentation and made an webview button in xml, and declared : 我试图从本地文件在android studio中实现我的Web应用程序/页面,我按照官方文档在xml中创建了webview按钮,并声明:
<uses-permission android:name="android.permission.INTERNET" />
in the manifest file. 在清单文件中。 My java activity code is below :
我的Java活动代码如下:
package samples.opencv.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview =(WebView)findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("file:///C:/Users/olive/OneDrive/Documents/ComputerScience/Project/Atom/index.html");
}
}
but i get the error on the emulator saying the webpage cannot be loaded as file is not found. 但是我在模拟器上收到错误消息,因为找不到文件,无法加载网页。
Put your web resources into the assets folder, usually under <project>/src/main/assets
, because emulator cannot see the file under your computer root ".../C:/Users/olive/OneDrive/Documents/ComputerScience/..."
将Web资源放入资产文件夹中,通常位于
<project>/src/main/assets
,因为仿真器无法在您的计算机根目录".../C:/Users/olive/OneDrive/Documents/ComputerScience/..."
下看到文件".../C:/Users/olive/OneDrive/Documents/ComputerScience/..."
then call: 然后致电:
webView.loadUrl("file:///android_asset/index.html");
Remember that in Android application, files can be read from 3 types of locations: 请记住,在Android应用程序中,可以从3种类型的位置读取文件:
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.