このクラスで WebView 例外が発生していますが、どの行が指定されていません。例外は次のとおりです。
java.lang.NullPointerException
at android.webkit.ZoomManager.onSizeChanged(ZoomManager.java:955)
at android.webkit.WebViewClassic.onSizeChanged(WebViewClassic.java:5634)
at android.webkit.WebView.onSizeChanged(WebView.java:2147)
at android.view.View.sizeChange(View.java:14400)
at android.view.View.setFrame(View.java:14375)
at android.webkit.WebView.access$701(WebView.java:239)
at android.webkit.WebView$PrivateAccess.super_setFrame(WebView.java:1778)
at android.webkit.WebViewClassic.setFrame(WebViewClassic.java:5610)
at android.webkit.WebView.setFrame(WebView.java:2141)
at android.view.View.layout(View.java:14286)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
コードは次のとおりです。
import com.flurry.android.FlurryAgent;
import utils.SendEmail;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.PluginState;
public class YoutubeActivity extends Activity
{
WebView webview = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
webview = new WebView(this);
setContentView(webview);
// long timeout = ViewConfiguration.getZoomControlsTimeout();
// new Timer().schedule(new TimerTask() {
// @Override
// public void run() {
// webview.destroy();
// }
// }, timeout);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(1);
webview.getSettings().setPluginState(PluginState.ON);
WebSettings webSettings = webview.getSettings();
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setBuiltInZoomControls(true);
//webSettings.setAllowContentAccess(true);
//webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
webview.setWebChromeClient(new WebChromeClient(){});
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webSettings.setDatabaseEnabled(true);
webSettings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
//webSettings.setUserAgentString("Dolphin");
//webview.loadUrl("http://javatester.org/javascript.html");
webview.loadUrl("http://www.youtube.com/user/Okudjavavich");
// webview.loadUrl("http://www.youtube.com/g33ktalktv");
}
@Override
public void onPause()
{
super.onPause();
// your code
webview.clearCache(true);
webview.getSettings().setAppCacheEnabled(false);
webview.clearView();
webview.stopLoading();
webview.destroy();
this.finish();
}
@Override
public void onDestroy()
{
super.onDestroy();
// your code
try
{
webview.getSettings().setBuiltInZoomControls(true);
}
catch ( Exception e )
{
}
}
@Override
public void onStop()
{
super.onStop();
// your code
FlurryAgent.onEndSession(this);
//webview.goBack();
try
{
webview.clearView();
webview.getSettings().setAppCacheEnabled(false);
webview.stopLoading();
webview.destroy();
}
catch ( Exception e )
{
}
this.finish();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack())
{
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
//@Override
public void onPageFinished(WebView view, String url)
{
//super.onPageFinished(view, url);
view.clearCache(true);
}
public void onBackPressed ( )
{
webview.clearView();
}
@Override
protected void onStart()
{
super.onStart();
FlurryAgent.onStartSession(this, "4VYNFK3V6RCZ53CZ3J32");
}
}
これは Android 4.3 で発生します。このクラッシュを止める方法を知っている人はいますか? 再現できませんが、クラッシュ レポートに表示されます。