我正在处理一个 Android 简单演示中的错误。当我单击菜单时,我有我的互联网检查例程和一个带有重新加载调用的 webview。这是我的代码
package com.example.test;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
public static final int DIALOG_NONETWORK = 0;
WebView mywebview=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView mywebview = (WebView) findViewById(R.id.webview);
if(!Connection()){
String data = "<html>" +
"<body><h1>NO INTERNET</h1></body>" +
"</html>";
mywebview.loadData(data, "text/html", "UTF-8");
Log.v("INTERNET","NO");
}else{
mywebview.loadUrl("http://www.google.com");
Log.v("INTERNET","YES");
}
mywebview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
String data = "<html>" +
"<body><h1>NO INTERNET</h1></body>" +
"</html>";
mywebview.loadData(data, "text/html", "UTF-8");
}
});
}
public boolean Connection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfoMob = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo netInfoWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if ((netInfoMob != null || netInfoWifi != null) && (netInfoMob.isConnectedOrConnecting() || netInfoWifi.isConnectedOrConnecting())) {
return true;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.action_settings:
mywebview.reload();
Log.v("INTERNET","RELOAD");
break;
}
return super.onOptionsItemSelected(item);
}
}
当我单击菜单“action_settings”时,应用程序在重新加载功能时崩溃。我怀疑它mywebview.setWebViewClient(new WebViewClient()
与final WebView mywebview = (WebView) findViewById(R.id.webview);
有什么帮助或建议吗?
04-10 17:41:03.537: E/ActivityThread(669): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce2948 that was originally bound here
04-10 17:41:03.537: E/ActivityThread(669): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce2948 that was originally bound here
04-10 17:41:03.537: E/ActivityThread(669): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-10 17:41:03.537: E/ActivityThread(669): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-10 17:41:03.537: E/ActivityThread(669): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-10 17:41:03.537: E/ActivityThread(669): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-10 17:41:03.537: E/ActivityThread(669): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-10 17:41:03.537: E/ActivityThread(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-10 17:41:03.537: E/ActivityThread(669): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-10 17:41:03.537: E/ActivityThread(669): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-10 17:41:03.537: E/ActivityThread(669): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-10 17:41:03.537: E/ActivityThread(669): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-10 17:41:03.537: E/ActivityThread(669): at java.lang.Thread.run(Thread.java:856)
04-10 17:41:03.557: E/StrictMode(669): null
04-10 17:41:03.557: E/StrictMode(669): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce2948 that was originally bound here
04-10 17:41:03.557: E/StrictMode(669): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-10 17:41:03.557: E/StrictMode(669): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-10 17:41:03.557: E/StrictMode(669): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-10 17:41:03.557: E/StrictMode(669): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-10 17:41:03.557: E/StrictMode(669): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-10 17:41:03.557: E/StrictMode(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-10 17:41:03.557: E/StrictMode(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-10 17:41:03.557: E/StrictMode(669): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
04-10 17:41:03.557: E/StrictMode(669): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
04-10 17:41:03.557: E/StrictMode(669): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
04-10 17:41:03.557: E/StrictMode(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-10 17:41:03.557: E/StrictMode(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-10 17:41:03.557: E/StrictMode(669): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-10 17:41:03.557: E/StrictMode(669): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-10 17:41:03.557: E/StrictMode(669): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-10 17:41:03.557: E/StrictMode(669): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-10 17:41:03.557: E/StrictMode(669): at java.lang.Thread.run(Thread.java:856)
04-10 17:41:03.657: E/ActivityThread(669): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cecbf8 that was originally bound here
04-10 17:41:03.657: E/ActivityThread(669): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cecbf8 that was originally bound here
04-10 17:41:03.657: E/ActivityThread(669): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-10 17:41:03.657: E/ActivityThread(669): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-10 17:41:03.657: E/ActivityThread(669): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-10 17:41:03.657: E/ActivityThread(669): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-10 17:41:03.657: E/ActivityThread(669): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-10 17:41:03.657: E/ActivityThread(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-10 17:41:03.657: E/ActivityThread(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-10 17:41:03.657: E/ActivityThread(669): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-10 17:41:03.657: E/ActivityThread(669): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-10 17:41:03.657: E/ActivityThread(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-10 17:41:03.657: E/ActivityThread(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-10 17:41:03.657: E/ActivityThread(669): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-10 17:41:03.657: E/ActivityThread(669): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-10 17:41:03.657: E/ActivityThread(669): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-10 17:41:03.657: E/ActivityThread(669): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-10 17:41:03.657: E/ActivityThread(669): at java.lang.Thread.run(Thread.java:856)
04-10 17:41:03.697: E/StrictMode(669): null
04-10 17:41:03.697: E/StrictMode(669): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cecbf8 that was originally bound here
04-10 17:41:03.697: E/StrictMode(669): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-10 17:41:03.697: E/StrictMode(669): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-10 17:41:03.697: E/StrictMode(669): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-10 17:41:03.697: E/StrictMode(669): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-10 17:41:03.697: E/StrictMode(669): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-10 17:41:03.697: E/StrictMode(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-10 17:41:03.697: E/StrictMode(669): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-10 17:41:03.697: E/StrictMode(669): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-10 17:41:03.697: E/StrictMode(669): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-10 17:41:03.697: E/StrictMode(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-10 17:41:03.697: E/StrictMode(669): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-10 17:41:03.697: E/StrictMode(669): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-10 17:41:03.697: E/StrictMode(669): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-10 17:41:03.697: E/StrictMode(669): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-10 17:41:03.697: E/StrictMode(669): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-10 17:41:03.697: E/StrictMode(669): at java.lang.Thread.run(Thread.java:856)