我试图在两个活动之间传递一个字符串.我在其他项目中使用相同的方法完成了这个,但由于某种原因,当我调用intent.getStringExtra(String)时,我得到一个NullPointerException.我也试过通过创建一个Bundle for extras
Bundle b = getIntent().getExtras();
Run Code Online (Sandbox Code Playgroud)
但那也返回了null.下面是我目前正在尝试使用的代码.
活动A:
Intent myIntent = null;
String select = "";
if (selection.equals("Chandelle")) {
myIntent = new Intent(Commercial.this, Chandelle.class);
select = "Chandelle";
} else if (selection.equals("Eights on Pylons")) {
myIntent = new Intent(Commercial.this, EightsOnPylons.class);
select = "Eights on Pylons";
}
// Start the activity
if (myIntent != null) {
myIntent.putExtra("selection", select);
Log.d("*** OUTBOUND INTENT: ", "" + myIntent.getExtras().get("selection"));
startActivity(myIntent);
}
Run Code Online (Sandbox Code Playgroud)
这是活动B中试图拉出额外内容的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
if (i == …Run Code Online (Sandbox Code Playgroud) 我正在学习smalltalk,我正在尝试创建一个非常简单的程序,创建一个数字数组,然后找到最大的数字.我的代码看起来像这样:
| list max |
list := #(1 8 4 5 3).
1 to: list size do: [:i |
max < (list at: i)
ifTrue: [max := (list at: i)].
ifFalse: [max := max].
].
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我得到"stdin:7:解析错误,预期']'".我对这导致什么感到困惑.它看起来像我的所有方括号对应.救命?