Skip to content Skip to sidebar Skip to footer

Java.lang.nullpointerexception: Android Attempt To Invoke Virtual Method Error

My android webview fragment app is getting crashed, after i have added a button to go from one fragment to another, the error on the console is: E/AndroidRuntime: FATAL EXCEPTION:

Solution 1:

Try below:

@OverridepublicvoidonAttach(Activity activity) {
super.onAttach(activity);
    mActivity = activity;
}

and then to prevent leaks:

@OverridepublicvoidonDetach() {
    super.onDetach();
    mContext = null;
}

Now to use MainActivity do:

((MainActivity)mContext).setUrl(url);

Post a Comment for "Java.lang.nullpointerexception: Android Attempt To Invoke Virtual Method Error"