[英]Android WebView LoadURL error in Android studio 3.0.1
我正在制作一個用於顯示網頁(就是這樣)的基本測試應用程序。
但是在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
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方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.