Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: android.os.Bundle.getString

Tags:

android

game.multiplayer = bundle.getString("multiplayer" ,null); 

is giving the error:

java.lang.NoSuchMethodError: android.os.Bundle.getString 

Other methods like

 game.word.word = bundle.getStringArray("word"); 

work fine.

Anyone any idea?

like image 518
user1104939 Avatar asked Jan 18 '12 19:01

user1104939


2 Answers

getString(key, defValue) was added in API 12. Use getString(key), as this will return null if the key doesn't exist.

like image 170
SimonVT Avatar answered Sep 22 '22 22:09

SimonVT


Just use this function:

public static String getStringFromBundle(Bundle bundle, String key, String defaultValue){     if (Build.VERSION.SDK_INT < 12){         String returns = bundle.getString(key);         if(returns==null) returns = defaultValue;          return returns;     } else         return bundle.getString(key, defaultValue); } 
like image 34
Maks Hameliak Avatar answered Sep 21 '22 22:09

Maks Hameliak