Crashing Fragment
-
22-12-2019 - |
Question
I am making a webview browser that uses sliding menu fragments. When I open this fragment then the app crashes. I am new to fragments so I apologize if this is nooby. If there's anything else I can do to help with this then just ask.
Below is the fragment class
public class WhatsHotFragment extends Fragment {
public WhatsHotFragment(){}
WebView WebViewB;
ProgressBar Pbar6;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_whats_hot, container, false);
Pbar6 = (ProgressBar) getView().findViewById(R.id.progBar6);
WebViewB = (WebView) getView().findViewById(R.id.wvBrowserAesir);
WebSettings webSettings = WebViewB.getSettings();
webSettings.setJavaScriptEnabled(true);
WebViewB.getSettings().setLoadWithOverviewMode(true);
WebViewB.getSettings().setUseWideViewPort(true);
WebViewB.getSettings().setBuiltInZoomControls(true);
WebViewB.getSettings().setAllowFileAccess(true);
WebViewB.setWebViewClient(new InsideWebViewClient());
WebViewB.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
if(progress < 100 && Pbar6.getVisibility() == ProgressBar.VISIBLE){
Pbar6.setVisibility(ProgressBar.VISIBLE);
}
Pbar6.setProgress(progress);
if(progress == 100) {
Pbar6.setVisibility(ProgressBar.VISIBLE);
}
}
});
{
WebViewB.loadUrl("http://www.google.com");
}
return rootView;
}
}
Thanks in advance!
Solution
Change to
Pbar6 = (ProgressBar) rootView.findViewById(R.id.progBar6);
WebViewB = (WebView) rootView.findViewById(R.id.wvBrowserAesir);
You can also use getView().findViewById
in onActivityCreated
to initialize your views.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow