HTC的WebView问题.getting强制关闭 [英] HTC webview issues .getting force close

查看:193
本文介绍了HTC的WebView问题.getting强制关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的自定义Web视图

 公共类MycustomWebView扩展的WebView {    公共静态布尔sClicked = FALSE;
    私人布尔mOverrideCheckIsTextEditor = TRUE;    公共查看mCross;//公共MycustomWebView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
//超(背景下,ATTRS,defStyle);
//}    公共MycustomWebView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,android.R.attr.webViewStyle);
    }
    公共MycustomWebView(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
    }    公共MycustomWebView(上下文的背景下){
        超级(上下文);
    }    @覆盖
    公共布尔onTouchEvent(MotionEvent EV){
        sClicked = TRUE;
        开关(ev.getAction()){
        案例MotionEvent.ACTION_DOWN:
        案例MotionEvent.ACTION_UP:
            如果(!hasFocus()){
                尝试{
                    requestFocus()方法;
                }赶上(例外五){
                    Toast.makeText(的getContext(),错误没有重点,Toast.LENGTH_SHORT).show();
                    Log.d(焦点问题,e.getMessage());
// Logger.v(不能获得焦点+ e.getMessage());
                }
            }
            打破;
        }
        尝试{
            //在某些设备崩溃
            返回super.onTouchEvent(EV);
        }赶上(例外五){
            返回false;
        }
    }
    @覆盖
    公共布尔onCheckIsTextEditor(){         如果(mOverrideCheckIsTextEditor){
                返回true;
            }其他{
                返回super.onCheckIsTextEditor();
            }    }    @覆盖
    公共无效使用loadURL(字符串URL){
        super.loadUrl(URL);
    }    公共无效setOverrideOnCheckIsTextEditor(布尔B){        mOverrideCheckIsTextEditor = B;
    }}

这是我的主要活动

 公共类MainActivity延伸活动{    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        的WebView myWebView =(的WebView)findViewById(R.id.myweb1);// myWebView =新的WebView(这一点,空,android.R.attr.webViewStyle,真正的);
        WebSettings webSettings = myWebView.getSettings();
        myWebView.setFocusable(真);
        myWebView.isFocusableInTouchMode();
        myWebView.requestFocus();
        webSettings.setJavaScriptEnabled(真);
        myWebView.loadUrl(http://developer.samsung.com/resources.do);
        }
}

这是我的XML code

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    工具:上下文=MainActivity。>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:文字=@字符串/参考hello world/>    < com.example.testproj.MycustomWebView
        机器人:ID =@ + ID / myweb1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:可聚焦=真
        机器人:layerType =软件/>       <! - < com.example.testproj.LiveWebView
        机器人:ID =@ + ID / myweb1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT        机器人:layerType =软件/> - >< / RelativeLayout的>

我的问题是,当我运行我的HTC设备的应用是越来越强制关闭,其中在其他设备,如承上启下它工作正常。任何一个请帮我。

这是错误日志

 致命异常:主要
 显示java.lang.NullPointerException
    在android.webkit.WebView $ PrivateHandler.handleMessage(WebView.java:9972)
    在android.os.Handler.dispatchMessage(Handler.java:99)
    在android.os.Looper.loop(Looper.java:156)
    在android.app.ActivityThread.main(ActivityThread.java:4987)
    在java.lang.reflect.Method.invokeNative(本机方法)
    在java.lang.reflect.Method.invoke(Method.java:511)
    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    在dalvik.system.NativeStart.main(本机方法)


解决方案

我有我自己解决了这个。我刚才评论此code

  @覆盖
    onCheckIsTextEditor(){         如果(mOverrideCheckIsTextEditor){
                返回true;
            }其他{
                返回super.onCheckIsTextEditor();
            }    }

,对我来说是工作。希望这将有助于其他

this is my custom web view

public class MycustomWebView extends WebView {

    public static boolean sClicked = false;
    private boolean mOverrideCheckIsTextEditor = true;

    public View mCross;

//  public MycustomWebView(Context context, AttributeSet attrs, int defStyle) {
//      super(context, attrs, defStyle);
//  }

    public MycustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, android.R.attr.webViewStyle);
    }


    public MycustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MycustomWebView(Context context) {
        super(context);
    }



    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        sClicked = true;
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
            if (!hasFocus()) {
                try {
                    requestFocus();
                } catch(Exception e){
                    Toast.makeText(getContext(), "error no focus", Toast.LENGTH_SHORT).show();
                    Log.d("Focus issue", e.getMessage());
//                  Logger.v("can't get focus " + e.getMessage());
                }
            }
            break;
        }
        try {
            // crashes on some devices
            return super.onTouchEvent(ev);
        } catch(Exception e){
            return false;
        }
    }
    @Override
    public boolean onCheckIsTextEditor() {

         if (mOverrideCheckIsTextEditor) {
                return true;
            } else {
                return super.onCheckIsTextEditor();
            }

    }

    @Override
    public void loadUrl(String url) {
        super.loadUrl(url);
    }



    public void setOverrideOnCheckIsTextEditor(boolean b) {

        mOverrideCheckIsTextEditor = b;
    }

}

this is my main activity

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView myWebView = (WebView) findViewById(R.id.myweb1);

//      myWebView=  new WebView(this, null, android.R.attr.webViewStyle, true);
        WebSettings webSettings = myWebView.getSettings();
        myWebView.setFocusable(true);
        myWebView.isFocusableInTouchMode();
        myWebView.requestFocus();
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("http://developer.samsung.com/resources.do");
        }
}

this is my XMl code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

    <com.example.testproj.MycustomWebView
        android:id="@+id/myweb1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:focusable="true"
        android:layerType="software" />

       <!--  <com.example.testproj.LiveWebView
        android:id="@+id/myweb1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:layerType="software" /> -->

</RelativeLayout>

my problem is when i am running my application in HTC device it is getting force close where as in other device such as nexus it is working fine . any one please help me

this is error log

FATAL EXCEPTION: main
 java.lang.NullPointerException
    at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:9972)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:4987)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

解决方案

i have solved this by myself .i have just commented this code

@Override
    onCheckIsTextEditor() {

         if (mOverrideCheckIsTextEditor) {
                return true;
            } else {
                return super.onCheckIsTextEditor();
            }

    }

and for me it is working. hope it will help others

这篇关于HTC的WebView问题.getting强制关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆