I have a WebViewFragment and when trying to get the webview to use, it gives me a null pointer
public class BallInfoFragment extends WebViewFragment {
long id;
public BallInfoFragment(long id){
this.id = id;
}
@Override
public void onCreate(Bundle state){
super.onCreate(state);
String ball = new String();
Cursor c = getActivity().getContentResolver().query(Balls.CONTENT_URI,new String[] {Balls.ID,Balls.BALL},Balls.ID+"="+id,null,null);
c.moveToFirst();
ball = c.getString(1);
WebView wv = getWebView(); //getWebView always gives me null
why is it null?
You have to put the code within the
onActivityCreated()function instead. This is called after theWebViewhas been instantiated.onCreateis called when the activity is created, before theWebViewhas been.