Home » Android » java – DisplayMessageActivity cannot be resolved to a type-Building first android App

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

Posted by: admin May 14, 2020 Leave a comment


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:


/**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.

How to&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.


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.



DisplayMessageActivity is not a class predifined by android packages, so you should create it as ordinary java class and call from yours, here, MainActivity. Sure it doesn’t require to be named as in the tutorial


You can create the display message activity class yourself by adding this code anywhere
public class DisplayMessageActivity {