gpt4 book ai didi

android - HTC webview 问题 .getting force close

转载 作者:行者123 更新时间:2023-11-30 03:43:43 24 4
gpt4 key购买 nike

这是我的自定义网页 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;
}

}

这是我的主要 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");
}
}

这是我的 XMl 代码

<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>

我的问题是,当我在 HTC 设备上运行我的应用程序时,它会强制关闭,而在其他设备(如 nexus)中它工作正常。任何人都请帮助我

这是错误日志

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)

最佳答案

我自己解决了这个问题。我刚刚评论了这段代码

@Override
onCheckIsTextEditor() {

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

}

对我来说它很管用。希望对其他人有帮助

关于android - HTC webview 问题 .getting force close,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15332650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com