我的操作栏中有按钮如下:
while (true) {
var info = collection.Take();
doStuff(info);
}
我在action_search中添加了onClick,以启动新活动。这是我的Java启动活动。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
app:showAsAction="ifRoom"
android:onClick="doubleBet"/>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="never" />
然后我在DisplayMessageActivity类中接收了这样的意图:
public void doubleBet(View view){
Intent intent = new Intent(this, DisplayMessageActivity.class);
String x = "Hello";
intent.putExtra("key", x); //Optional parameters
startActivity(intent);
}
然而,当我运行它时,应用程序崩溃了。可能是什么原因造成的?
这是logcat:
答案 0 :(得分:2)
尝试更改$PORT
方法:
doubleBet
到此:
public void doubleBet(View view){
Intent intent = new Intent(this, DisplayMessageActivity.class);
String x = "Hello";
intent.putExtra("key", x); //Optional parameters
startActivity(intent);
}