sud007
sud007

Reputation: 6141

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

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.

Upvotes: 13

Views: 24210

Answers (4)

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

Upvotes: 5

JongAm Park
JongAm Park

Reputation: 613

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.

Upvotes: 32

Faizan Abrar
Faizan Abrar

Reputation: 1

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

Upvotes: 0

Yauhen
Yauhen

Reputation: 2535

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

Upvotes: 0

Related Questions