【问题标题】:Android WebView LoadURL error in Android studio 3.0.1Android Studio 3.0.1 中的 Android WebView LoadURL 错误
【发布时间】:2018-06-25 15:41:50
【问题描述】:

我正在制作一个显示网页(仅此而已)的基本测试应用程序。

但在 MainActivity.java 中,loadURL 出现“无法解析符号”错误,而 Atl+Enter 什么也不做。

WebView myWebView = (WebView) findViewById(R.id.webView);
        myWebView.loadUrl("WEBSITE");

在 MainActivity.xml 中:

<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

AndroidManifest.xml

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

这就是我输入的全部代码。

很确定这些是日志

BUILD FAILED in 14s

15 actionable tasks: 14 executed, 1 up-to-date
Executing tasks: [:app:assembleDebug]

:app:buildInfoDebugLoader
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:createDebugCompatibleScreenManifests UP-TO-DATE
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug UP-TO-DATE
:app:processDebugResources
:app:generateDebugSources
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavac
C:\Users\Simon\AndroidStudioProjects\Project7io\app\src\main\java\com\example\simon\project7io\MainActivity.java:19: error: <identifier> expected
myWebView.loadUrl("http://project7.io");
                 ^
C:\Users\Simon\AndroidStudioProjects\Project7io\app\src\main\java\com\example\simon\project7io\MainActivity.java:19: error: illegal start of type
myWebView.loadUrl("http://project7.io");
                  ^
2 errors

 FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

【问题讨论】:

  • 你在导入正确的 - import android.webkit.WebView; ?
  • 是的。它是进口的。还是不行,我在错误中添加了
  • 你可以从 logcat 中粘贴错误而不是图像。由于图像不完整。
  • 完成。怎么样?
  • 是的,关于 webView 的 google 教程...

标签: java android android-studio webview android-studio-3.0


【解决方案1】:
public class YourActivity extends AppCompatActivity {
    WebView myWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yourlayout);
        myWebView = (WebView) findViewById(R.id.webView);
        myWebView.loadUrl("https://example.com/");
    }
}

你应该在 onCreate() 中调用 loadUrl 方法

【讨论】:

猜你喜欢
  • 2018-05-06
  • 2013-08-24
  • 2018-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多