Android Error On Tutorial Cannot Find Symbol Variable Activity_display_message
Solution 1:
I had this same problem. Under the "Build an Intent" section in the Android Studio instructions, it's easy to miss this line:
publicfinalstaticStringEXTRA_MESSAGE="com.example.myfirstapp.MESSAGE";
Make sure this is included above the @Override in MainActivity.java and you're all set :)
Solution 2:
Don't know if anyone still need the answer to this, but I figured it out like this:
I saw this in the tutorial:
Note: The XML layout generated by previous versions of Android Studio might not include the android:id attribute. The call findViewById() will fail if the layout does not have the android:id attribute. If this is the case, open activity_display_message.xml and add the attribute android:id="@+id/activity_display_message" to the layout element.
So, under Res -> layout -> activity_display_message.xml, I entered the line
android:id="@+id/activity_display_message"
Anywhere inside the RelativeLayout tags. In my case specifically, I randomly shoved it in-between the android:paddingTop and tools:context fields
Hope this helps :D
Solution 3:
I think:
ViewGrouplayout= (ViewGroup) findViewById(R.id.activity_display_message);
Should be:
RelativeLayoutlayout= (RelativeLayout ) findViewById(R.id.content);
Solution 4:
Here is the updated solution for this.
Intent is a subclass of Main Activity so there's no need to specify explicitly. That means we can call EXTRA_MESSAGE
, instead of MainActivity.
EXTRA_MESSAGE
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Intentintent= getIntent();
Stringmessage= intent.getStringExtra(EXTRA_MESSAGE);
TextViewtextView=newTextView(this);
textView.setTextSize(40);
textView.setText(message);
ViewGrouplayout= (ViewGroup) findViewById(R.id.activity_display_message);
layout.addView(textView);
Solution 5:
I have solved the same issue by clean project and then Build the gradle, please try once.
Post a Comment for "Android Error On Tutorial Cannot Find Symbol Variable Activity_display_message"