一些外出应用程序的用户抱怨nullpointerexception,这似乎只发生在他们身上(HTC Desire,最新的Android,2.3?)但在其他设备上无法重现。我有点疑惑它的来源是什么。
有什么想法吗?
java.lang.NullPointerException
android.webkit.WebView.navHandledKey(WebView.java:9290)
android.webkit.WebView.requestFocus(WebView.java:7847)
android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1131)
android.view.ViewGroup.requestFocus(ViewGroup.java:1087)
android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1131)
android.view.ViewGroup.requestFocus(ViewGroup.java:1087)
android.view.View.requestFocus(View.java:3718)
android.view.View.requestFocus(View.java:3696)
android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1785)
android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:470)
android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:470)
android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:470)
android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:470)
android.view.View.setFlags(View.java:4680)
android.view.View.setVisibility(View.java:3163)
at com.ichi2.anki.Reviewer.fillFlashcard(Reviewer.java:2282)
代码如下:
private FrameLayout mCardContainer;
...
mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
...
mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
mCardFrame.removeAllViews();
mCard = createWebView();
mCardFrame.addView(mCard);
...
mCardContainer.setVisibility(View.VISIBLE); --> 2282
...
...
private WebView createWebView() {
WebView webView = new MyWebView(this);
webView.setWillNotCacheDrawing(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
if (mZoomEnabled) {
webView.getSettings().setBuiltInZoomControls(true);
}
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new AnkiDroidWebChromeClient());
webView.addJavascriptInterface(new JavaScriptInterface(), "interface");
if (Integer.parseInt(android.os.Build.VERSION.SDK) > 7) {
webView.setFocusableInTouchMode(false);
}
mScaleInPercent = webView.getScale();
return webView;
}
...
class MyWebView extends WebView {
public MyWebView(Context context) {
super(context);
}
@Override
public boolean onCheckIsTextEditor() {
return true;
}
}
相应的xml文件看起来像这样:
...
<FrameLayout android:id="@+id/flashcard_frame"
android:layout_margin="3dip"
android:layout_below="@+id/top_bar"
android:layout_above="@+id/answer_nextTime_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:id="@+id/flashcard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:id="@+id/touch_layer"
android:layout_marginTop="20dip"
android:longClickable="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<FrameLayout android:id="@+id/whiteboard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<ImageView android:id="@+id/lookup_button"
android:padding="5dip"
android:layout_gravity="right"
android:src="@drawable/ic_lookup"
android:visibility="gone"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<FrameLayout android:id="@+id/flashcard_border"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
...
答案 0 :(得分:0)
是行:
mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
mCardContainer.setVisibility(View.VISIBLE); --> 2282
致电setContentView(R.layout.your_proper_layout_resource);
后?