Я часто получаю кр sh с
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{com.example.phocast/com.example.phocast.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
AndroidStudio также показывает, что Method invocation .toString may produce NullPointException
Мой код:
public class SunFragment extends Fragment {
ArrayList<Object> sunsList;
Typeface sunfont;
Double Dlat;
Double Dlang;
private AdView mAdView;
//to be called by the MainActivity
public SunFragment() {
// Required empty public constructor
}
private static final String KEY_LOCATION_NAME = "location_name";
public String TAG = "SunFragment";
public String location;//="No location name found";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
location = savedInstanceState.getCharSequence(KEY_LOCATION_NAME).toString();
} else {
location = "";
}
}
Так как я уже проверяю savedInstanceState
, что еще я могу проверить?