조각 내부의 webview에 문제가 있습니다. "java.lang.nullpointerexception"이라는 오류 메시지가 표시됩니다. myWebView.setWebViewClient (new WebViewClient());. 나는 인터넷 검색을하고 봤지만 해결책을 찾지 못했습니다. 내가 누락 된 것에 대한 어떤 아이디어라도 있니?조각 내 webview의 nullpointerexception
FragmentB.java
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
/**
* A simple {@link Fragment} subclass.
*
*/
@SuppressLint("SetJavaScriptEnabled")
public class FragmentB extends Fragment {
public FragmentB() {
// Required empty public constructor
}
private View mContentView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mContentView = inflater.inflate(R.layout.fragment_b, container, false);
WebView myWebView = (WebView)mContentView. findViewById(R.id.webView);
myWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.nellienova.com");
return mContentView;
}
}
webview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
맞습니다. fragment_b.xml은 "단편 B"라는 임시 텍스트 뷰가있는 단편 레이아웃입니다. webview.xml은 위와 같이 webview 레이아웃입니다. 후자는 id "webview"를 가지며 webview에 사용됩니다. 나는 이것이 올바른 방법으로하고 있는지 확신 할 수 없다. 4 개의 조각 (A-D)이있는 스 와이프 탭 레이아웃이 있고 B 단편 안에 웹 사이트의 콘텐츠를 표시하고 싶습니다. – sebbenator
WebView가 R.layout.fragment_b 파일 안에 있다고 말하는 것입니까? 그렇지 않다면 그곳으로 이동하여 오류가 계속 발생하는지 확인하십시오. – dsum27
아니요, 저는 그것들을 두 개의 분리 된 파일에 보관했습니다. fragment_b 파일 안에 webview를 배치하자마자 그것은 매력처럼 작동했습니다! 도와 주셔서 감사합니다! – sebbenator