Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DisplayMessageActivity cannot be resolved to a type-Building first android App

Tags:

java

android

Hi I have just began working on the first android application on developer.android.com.

well to start with I got to learn many error origins and their solutions from S.O. , but i have been trying to figure out this statement "DisplayMessageActivity cannot be resolved to a type" while we have to set an Intent for button onclick function. It shows this error in the line where the code line is:

Intent intent = new Intent (this, DisplayMessageActivity.class);

here is the java file:

MainActivity.java

}
/**called when the user clicks the send button*/
public void sendMessage(View view) {
    Intent intent = new Intent (this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById (R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity (intent);
}
}

I tried a lot find which class do I need to import now, and searched but no avail. may be I am a beginner is what I miss here.

like image 607
sud007 Avatar asked Nov 02 '12 06:11

sud007


2 Answers

Well, I think it's too late to answer and probably you figured out already. However, just in case I'd like to put some more explanation.

Probably their "Starting Another Activity" section of Buidling Your First App" was revised after you posted your question, but I found that the user-defined "DisplayMessageActivity" is defined several lines below where you were guided to write code to create Intent and thus refer to DisplayMessageActivity. At "Create Second Activity" section, the DisplayMessageActivity is created.

Well, Google's pedagogy style is not good, and I found out that their framework design ( and thus naming ) is not good and doesn't reveal what they are. But.. if you choose Android platform to develop for, what can you do other than endure that. Good luck with that.

like image 105
JongAm Park Avatar answered Nov 15 '22 18:11

JongAm Park


In that tutorial of developing first app, they create DisplayMessageActivity.java later part of tutorial. Please read the complete tutorial. The documentation have been corrected to indicate the same when using IDEs. You can visit here :

Note: The reference to DisplayMessageActivity will raise an error if you’re using an IDE such as Eclipse because the class doesn’t exist yet. Ignore the error for now; you’ll create the class soon.

http://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent

like image 38
Balaji Boggaram Ramanarayan Avatar answered Nov 15 '22 19:11

Balaji Boggaram Ramanarayan