请帮帮我
我的网页浏览器存在问题 它最近工作,然后几天不工作,我不知道发生了什么 我再次运行它 只显示白页/空白页
这是我的代码
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new MyWebViewClient());
webview.loadUrl("www.google.com");
if (getIntent().getBooleanExtra("EXIT", false)) {
MainActivity.this.finish();
System.exit(0);
}
}
public class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
//To Prevent Web page not available
if (errorCode == -2) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(false);
builder.setTitle(Html.fromHtml("<font color='#7F02AE'><b>Your Project</b></font>"));
builder.setMessage(Html.fromHtml("<font color='#120049'>Your data services are not working.Please check your data services.</font>"));
builder.setPositiveButton(Html.fromHtml("<font color='#7F02AE'><b>OK</b></font>"), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// In Case of Fragment instead of Activity Replace getApplicationContext() with getActivity()
MainActivity.this.finish();
dialog.dismiss();
}
});
builder.setNegativeButton(Html.fromHtml("<font color='#7F02AE'><b>Retry</b></font>"), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", false);
startActivity(intent);
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
}
这是我的AndroidManifest.xml
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/app"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我试图再次寻找关于webview的基本教程,也许我错过了一些东西,但是当我尝试的时候 他们都只是一个空白页面 什么都没有显示我的 android studio遇到了问题