ok, so I am going through the tutorial of the \"MyFirstApp\" on the devoloper.android.com site. I am on the last tutorial and I have did everything for the first chapter you
I think you're getting the message from the intent the wrong way. EXTRA_MESSAGE
is the content and message
is the identifier.
So your code on DisplayMessageActivity.java
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
should actually be:
String message = intent.getStringExtra(message);
You can see in your activity_main.xml you have to declare button with onClick()
this way then and then it will be work.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:onClick="sendMessage()"/>
</LinearLayout>
It looks like you misspelled the function name in your xml for the Button onClick()
. You have an uppercase "m" in your java code
public void sendMessage(View view) {
and probably a lowercase "m" in your xml
<Button
...
android:onClick="sendmessage"/>
To comply with java standards, change it in your xml to
android:onClick="sendMessage"/>