Cannot find symbol method loadUrl(String)

依然范特西╮ 提交于 2020-01-17 14:04:25

问题


I am new to Android Studio. When I try to make this project it throws me the error:

Cannot find symbol method loadUrl(String) in the MainActivity.java.

The loadUrl is highlighted in red. I've made a folder assets in the main and added www folder in the assests folder.

package com.rmworks.digitalindia;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;



public class MainActivity extends AppCompatActivity {

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");

    }
}

回答1:


You have to add a WebView object like this:

In your layout.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

Then in MainActivity.java use this:

WebView webViewer = (WebView) findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/www/index.html");

Obviously you have to add permission

<uses-permission android:name="android.permission.INTERNET" />

Read this WebView for a better explanation

If you want to use super.loadUrl(String) you have to import org.apache.cordova.*, read this PhoneGap API



来源:https://stackoverflow.com/questions/33745480/cannot-find-symbol-method-loadurlstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!