WebTextView无法强制转换为android.view.SurfaceView

时间:2013-03-07 08:21:10

标签: android webview surfaceview

我将SurfaceView设置为webview,就像那样:

wv.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {  
        @Override
        public void onChildViewRemoved(View parent, View child) {}
        @Override
        public void onChildViewAdded(View parent, View child) {
            if(child.getClass().getName().equals("com.adobe.flashplayer.FlashPaintSurface")){
                Log.i("flash", "surface is open");
                ((SurfaceView)child).setZOrderOnTop(false); 
                ((SurfaceView)child).dispatchWindowFocusChanged(isHidden());
        }}
    });

但是...

当我点击WebViewText时,尝试写一些我的应用程序崩溃的东西,并显示错误日志:

03-07 10:14:37.425: E/AndroidRuntime(7378): FATAL EXCEPTION: main
03-07 10:14:37.425: E/AndroidRuntime(7378): java.lang.ClassCastException: android.webkit.WebTextView cannot be cast to android.view.SurfaceView

我是白痴 - 忘了把括号if(){}。请不要降低我的费率!

1 个答案:

答案 0 :(得分:2)

您在if ...

之后缺少括号
wv.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {  
    @Override
    public void onChildViewRemoved(View parent, View child) {}
    @Override
    public void onChildViewAdded(View parent, View child) {
        if(child.getClass().getName().equals("com.adobe.flashplayer.FlashPaintSurface")) {
            Log.i("flash", "surface is open");
            ((SurfaceView)child).setZOrderOnTop(false); 
            ((SurfaceView)child).dispatchWindowFocusChanged(isHidden());
        }
    }
});