Reputation: 351
I'm completely new to Android Studio.
I have just installed it on Windows 10 and since I wanted to learn how to use it, I have started to follow the online guide (https://developer.android.com/training/basics/firstapp/starting-activity.html#Up).
I am literally following it step by step, but when it comes to this part of the code:
public class DisplayMessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Capture the layout's TextView and set the string as its text
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(message);
}
the "textView" part after "findViewById" appears red and I get this error message: "cannot resolve symbol 'textView'".
This happens even if I have imported android.widget.TextView.
Maybe this is stupid question, but I am completely new to Android Studio. Thanks for the answers :)
Upvotes: 2
Views: 16352
Reputation: 1
After tiresome searches and updating settings, I Just clicked Invalidate Catches -> Invalidate And Restart And Done! TextView Error Disappearedenter image description here
Upvotes: 0
Reputation: 11
Erase the statement, then retype it. There is going to be a small pop up indicating you to press a command. It is basically an import library issue when you press the command (for macOS it is ⌥⏎ ) the respective library will be added. If this does not work, close Android Studio and reopen it . I am not an expert on this matter, but this worked for me hence I am sharing.
Upvotes: 0
Reputation: 1
The TextView object of the Activity_display_message is called TextView2, instead of Textview. So I tried and changed:
TextView textView = (TextView) findViewById(R.id.textView);
for
TextView textView = (TextView) findViewById(R.id.textView2);
And it worked!
Upvotes: 0
Reputation: 91
In my case, the problem was for other reason although the error was the same. I copied the following code out of the OnCreate method.
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Capture the layout's TextView and set the string as its text
TextView textView = findViewById(R.id.textView);
textView.setText(message);
The text (TextView) before findViewById was not neccesary.
Upvotes: 0
Reputation: 66
As mentioned by buutqn
<TextView>
tag must haveandroid:id="@+id/textView"
This is in the file: app.res.layout.activity_display_message.xml under the Text tab(as opposed to Design tab).
This issue can be duplicated by deleting the TextView box from the design tab, and inserting a new (second) text view.
Upvotes: 1
Reputation: 448
In your file R.layout.activity_display_message, the <TextView>
tag must have android:id="@+id/textView"
Can you include your XML File?
Upvotes: 4