Saturday, 17 August 2013

Unfortunately, First Project has stopped

Unfortunately, First Project has stopped

I am trying to learn android development and and I have a problem. I study
the tutorials on the Android site. I try to send a message so I can see it
on my screen but the message "Unfortunately, First Project has stopped"
appears suddenly.
Here is my code for Mainactivity.java
package com.example.firstproject;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.content.Intent;
import android.widget.EditText;
//import android.text.*;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE =
"com.example.firstproject.MESSAGE";
/** In order for the next activity to query the extra data */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
/**findViewById() to get the EditText element and add its text
value to the intent*/
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
Any idea what is the problem and how can I solve it?

No comments:

Post a Comment