Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError Bundle.getString()

Tags:

android

I get some wierd logs, which obviously only occurs on Android-Devices with Versions below 3(checked with emulator). When you change the orientation and onCreate() or onRestoreInstanceState() is called with an Bundle that is not null it crashed

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);}
    if (savedInstanceState != null) {
        mSlug = savedInstanceState.getString(KEY_SLUG, null);
    }
}@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString(KEY_SLUG, mSlug);
}@Override
protected void onRestoreInstanceState(Bundle outState) {
    super.onRestoreInstanceState(outState);
    if (outState != null) {
        mSlug = outState.getString(KEY_SLUG, mSlug);
    }
}

The LogCat-Log looks like: https://i.sstatic.net/WbivQ.png Does anybody got clue what is happening here?

like image 863
LeDon Avatar asked Jan 26 '26 20:01

LeDon


1 Answers

Bundle.getString with 2 arguments is only available in API level 12 and later. You have to specify the default value yourself, rather than passing it as an argument.

You can check this yourself in the future by clicking the "Filter by API level" dropdown and selecting the appropriate API level in the upper right hand of the documentation

like image 191
Codeman Avatar answered Jan 28 '26 15:01

Codeman