java - error: reached end of file while parsing in Android Studio
问题描述
This is my 1st time using Java and Android, I’m trying to launch a simple application with WebView
script.
Everything was okay but I am facing issue when I’m trying to add loading bar for my web view page. The problem:
error: reached end of file while parsing
I’m using this code for Mainactivity
package com.example.last;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private WebView webView;
private ProgressBar mProgressbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView =(WebView) findViewById(R.id.WebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mProgressbar=findViewById(R.id.progressBar);
mProgressbar.setMax(100);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://beko963.000webhostapp.com");
webView.setWebViewClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
mProgressbar.setProgress(newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
@Override
public void onReceivedIcon(WebView view, Bitmap icon) {
super.onReceivedIcon(view, icon);
}
}}
@Override
public void onBackPressed () {
if (webView.canGoBack()) {
webView.goBack();
} else
super.onBackPressed();
}}
And using this for main XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/progressBar"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />
<WebView
android:id="@+id/WebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
I just want to make a simple application with loading icon, could you please help my and fix my code?
解决方案
正如约翰和其他人所说
webView.setWebViewClient(new WebChromeClient() {}}
结束在哪里)
//replace last } with );
webView.setWebViewClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
mProgressbar.setProgress(newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
@Override
public void onReceivedIcon(WebView view, Bitmap icon) {
super.onReceivedIcon(view, icon);
}
});
推荐阅读
- python - 从 Dataframe 的 4 列创建 3D 矩阵
- bash - 如何在不使用文件的情况下拆分/复制 FIFO
- javascript - 如何在 Nodejs 中正确使用相等运算符
- javascript - GET 或 POST 请求 => 很长的 URL
- c# - 反序列化日期时间字符串而不进行任何格式操作
- javascript - 在 Visual Studio 2019 中进行发布构建时,有没有办法从 js 文件中删除调试器和 console.log 语句?
- c++ - 如何正确地将点积与 MPI_Scatter 并行化?
- javascript - 玩家靠近时子弹弯曲
- discord.js - 带有 id 的 discord.js V12 userinfo 命令
- c# - Aspnet Zero Nswag 生成服务代理