我试图从一个意图传递到另一个通过一些String。 但ADT说:
密钥文本字符串预期值却是一个android.text.SpannableString。 默认值返回。
但我使用一个String作为关键不是它所声称!
这里是我的第一个活动的代码:
private int CONTACTS_ACTIVITY_REQUEST = 1001;
public static final String TEXT_KEY = "text";
...
Intent intent = new Intent(this, ContactsActivity.class);
intent.putExtra(TEXT_KEY, text.getText());
startActivityForResult(intent, CONTACTS_ACTIVITY_REQUEST);
我的第二个活动:
Intent intent = this.getIntent();
text = intent.getStringExtra(MainActivity.TEXT_KEY);
谢谢。
PS这里是完整的堆栈跟踪:
03-22 14:51:32.975: W/Bundle(1248): Key text expected String but value was a android.text.SpannableString. The default value <null> was returned.
03-22 14:51:33.006: W/Bundle(1248): Attempt to cast generated internal exception:
03-22 14:51:33.006: W/Bundle(1248): java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String
03-22 14:51:33.006: W/Bundle(1248): at android.os.Bundle.getString(Bundle.java:1085) 03-22 14:51:33.006: W/Bundle(1248): at android.content.Intent.getStringExtra(Intent.java:4473)
03-22 14:51:33.006: W/Bundle(1248): at com.saeedFri.groupsms.ContactsActivity.onCreate(ContactsActivity.java:39)
03-22 14:51:33.006: W/Bundle(1248): at android.app.Activity.performCreate(Activity.java:5133)
03-22 14:51:33.006: W/Bundle(1248): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-22 14:51:33.006: W/Bundle(1248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-22 14:51:33.006: W/Bundle(1248): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-22 14:51:33.006: W/Bundle(1248): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-22 14:51:33.006: W/Bundle(1248): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-22 14:51:33.006: W/Bundle(1248): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 14:51:33.006: W/Bundle(1248): at android.os.Looper.loop(Looper.java:137)
03-22 14:51:33.006: W/Bundle(1248): at android.app.ActivityThread.main(ActivityThread.java:5103)
03-22 14:51:33.006: W/Bundle(1248): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 14:51:33.006: W/Bundle(1248): at java.lang.reflect.Method.invoke(Method.java:525)
03-22 14:51:33.006: W/Bundle(1248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-22 14:51:33.006: W/Bundle(1248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-22 14:51:33.006: W/Bundle(1248): at dalvik.system.NativeStart.main(Native Method)