[英]Android WebView LoadURL error in Android studio 3.0.1
I am making a basic app for testing that displays a web page (and that's it). 我正在制作一个用于显示网页(就是这样)的基本测试应用程序。
But in MainActivity.java, loadURL gets a "can not resolve symbol" error and Atl+Enter does nothing. 但是在MainActivity.java中,loadURL出现“无法解析符号”错误,而Atl + Enter则不执行任何操作。
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl("WEBSITE");
In MainActivity.xml: 在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 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
And that's all the code I put in. 这就是我输入的所有代码。
Pretty sure these are the logs 可以肯定的是这些是日志
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
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/");
}
}
You should be calling loadUrl method inside onCreate() 您应该在onCreate()中调用loadUrl方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.